39

I have a repo in bitbucket, and i am using git.

So my branches are

master
develop_one
develop_two

When i use git clone git@bitbucket.org:project/project.git, i am getting only the master branch code, but i need to clone/pull only develop_one branch, so how to clone/pull only develop_one branch code ?

Note: The other branches(develop_one, develop_two) are not merged in to master, and dont want to merge until the functionality has been completed actually, so want to get/clone/pull only a specific branch code

Shiva Krishna Bavandla
  • 25,548
  • 75
  • 193
  • 313
  • 3
    possible duplicate of [Clone only one branch](http://stackoverflow.com/questions/4811434/clone-only-one-branch) – RyPeck Nov 17 '13 at 17:51
  • To clarify - do you want to clone or just pull from a single branch? Two different questions. – RyPeck Nov 17 '13 at 17:52
  • Possible duplicate of [How to clone a single branch in git?](https://stackoverflow.com/questions/1778088/how-to-clone-a-single-branch-in-git) – Jon Schneider Aug 17 '18 at 21:22

2 Answers2

74

Try:

git clone git@bitbucket.org:project/project.git -b develop_one --single-branch

For already cloned repos use:

git fetch
git checkout develop_one
# Or more specific:
git checkout --track -b develop_one

This will track the develop_one branch from the remote.

tombruijn
  • 1,130
  • 10
  • 13
  • I get `error: unknown option single-branch` when I do the the command you mention. What version of git are you running? – Anshul Goyal Nov 17 '13 at 17:50
  • `git --version` returns `git version 1.8.4.2` (just one patch release behind I see) – tombruijn Nov 17 '13 at 17:51
  • 3
    Oh Ok. `--single-branch` came in [`1.7.10`](https://raw.github.com/gitster/git/master/Documentation/RelNotes/1.7.10.txt) and I am on `1.7.9.5`. What an edge case :) – Anshul Goyal Nov 17 '13 at 17:54
11

Also, to add to @tomrbrujin 's answer, you can specify the name of the local destination directory in the clone command like this:

git clone https://github.com/example/example1.git -b branch_name --single-branch local_name

The final arg passed, local_name would create and name the local copy of the cloned remote directory "local_name."

Otherwise, the local directory name will only reflect the repo name, which here would be: example

eulerworks
  • 365
  • 3
  • 8