52

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?

sfletche
  • 47,248
  • 30
  • 103
  • 119
ruby student
  • 1,059
  • 4
  • 12
  • 18

7 Answers7

46

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
sfletche
  • 47,248
  • 30
  • 103
  • 119
44
git clone -b branchName remote_repo_url

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

Floern
  • 33,559
  • 24
  • 104
  • 119
12

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

Rahul
  • 3,293
  • 2
  • 31
  • 43
Sourabh Dev
  • 743
  • 11
  • 22
9

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.

Vishu
  • 331
  • 3
  • 3
2

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.

Satyam Anand
  • 437
  • 4
  • 11
1

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
Sameer
  • 113
  • 1
  • 4
0

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

Cheolsoon Im
  • 716
  • 1
  • 6
  • 11