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?

chipbk10
  • 5,783
  • 12
  • 49
  • 85
  • 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 '16 at 08:20
  • @ckruczek according to https://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 '16 at 08: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 '16 at 08:35

2 Answers2

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

DBX12
  • 2,041
  • 1
  • 15
  • 25
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.

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60