ruby student
ruby student

Reputation: 1129

How to clone a specific branch in git bitbucket

I want to clone a specific branch. I don't want download the master branch.

How do I clone the whole project and then switch to validations branch?

Upvotes: 53

Views: 127470

Answers (7)

Cheolsoon Im
Cheolsoon Im

Reputation: 726

Are you using Sourcetree? If so, select three dots and choose "Checkout in Sourcetree" And then Clone it.

Upvotes: 0

Sameer
Sameer

Reputation: 113

Using below command not only you can clone specific branch from origin but also create and checkout locally at same time

To see remote branches do

git branch -r 

Then

git checkout -b <local branch name> origin/<branch name>
example: git checkout -b Bug_1 origin/Develop

Upvotes: 1

Satyam Anand
Satyam Anand

Reputation: 507

once you're done adding your ssh key, you can follow up with: git clone -b <branch_name> <url_to_repository>

replace all angular brackets with your required branch name and repository URL.

Upvotes: 2

Sourabh Dev
Sourabh Dev

Reputation: 743

To pull a separate branch, you need to follow two simple steps.

1. Create a new branch

2. Pull the required branch

Try using the following commands:

git checkout -b <new-branch-name>
git pull origin <branch-to-pull>

You will now have all the contents in the <new-branch-name> branch

Upvotes: 12

mohamed murashid
mohamed murashid

Reputation: 719

git clone -b branchName remote_repo_url

For example git clone -b develop https://github.com/SundeepK/CompactCalendarView.git

Upvotes: 47

Vishu
Vishu

Reputation: 341

Use git clone as following :

git clone -b specific/Branch --single-branch git://sub.domain.com/repo.git

And, Helpful link is

https://git-scm.com/docs/git-clone/1.7.10

Also, If you get an error with "--single-branch", then removed it -b will work for you.

Upvotes: 9

sfletche
sfletche

Reputation: 49774

You can clone a single branch (without inadvertently cloning the whole project) with the following:

git clone <url> --branch <branch> --single-branch [<folder>]

Alternatively (attempting to address your new question here...), you can clone the whole project

git clone <url> 

Change directories into the folder and creating a new branch off of master with

git checkout -b validations

Upvotes: 47

Related Questions