0

When cloning a git repository, actually from which branch I did clone?

I mean on my git server, there are many branches: master, develop, features, bugs.

When I clone the project, I clone from which branch? I want to clone from the develop branch. How can I do that?

3
  • You can't clone from a specific branch. You can only clone the repo and then switch branches where you want to work on.
    – ckruczek
    Aug 31, 2016 at 8:20
  • @ckruczek according to lkml.org/lkml/2012/3/28/418 it is possible to clone a single branch. I guess without specifying --single-branch git clones the complete repository and switches to the master branch per default.
    – DBX12
    Aug 31, 2016 at 8:23
  • @DBX12 Yes thats true, anyway I am not a fan of just cloning a particular branch as I see git as a history tracking tool and I want to see the whole history. But this is just a personal perspective.
    – ckruczek
    Aug 31, 2016 at 8:35

2 Answers 2

1

You can clone a specific branch by adding the parameter --single-branch and the branch name by -b <branch name>

A clone command to clone the branch develop to the current working directory would look like this:

git clone -b develop --single-branch git://my.repository.url

Source: Documentation of git clone

2
  • This is not what I ask? I ask: when you clone, which branch did you clone? It's not the way to clone a specific branch.
    – chipbk10
    Aug 31, 2016 at 8:45
  • Sorry, I misunderstood your question then.
    – DBX12
    Aug 31, 2016 at 11:23
0

By default, following the clone operation, you will be on the branch that has been marked as the default branch within the git configuration. Assuming for instance you are using GitHub this is configurable through the Settings page:

enter image description here

Once you have cloned the repository, you can then do git checkout <branchname> to move into the branch that you are interested in.

Alternatively, you can change the default branch, if that makes sense for you, and your team.

2

Not the answer you're looking for? Browse other questions tagged or ask your own question.