How can I specify which branch should be checked out in a fresh clone?

只谈情不闲聊 提交于 2019-12-02 16:11:37

问题


In Git Extensions, the user can, when cloning a repository, specify which branch (possibly other than master) should be checked out in the resulting clone.

How can I do that at the command line?


回答1:


The answer, as often, is in the man pages (in the git-clone man page, here):

--branch <name>, -b <name>

    Instead of pointing the newly created HEAD to the branch pointed
    to by the cloned repository's HEAD, point to <name> branch
    instead. In a non-bare repository, this is the branch that will
    be checked out.  --branch can also take tags and detaches the
    HEAD at that commit in the resulting repository.

So you want to run

git clone --branch <name> <repository>

where <name> stands for the name of the branch that you want checked out in your clone of <repository>.


Example

$ cd ~/Desktop
$ git clone --branch maint https://github.com/git/git
$ cd git
$ git branch
* maint


来源:https://stackoverflow.com/questions/26238572/how-can-i-specify-which-branch-should-be-checked-out-in-a-fresh-clone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!