如何指定应在新克隆中检出哪个分支?

时间:2014-10-07 14:36:03

标签: git git-clone git-extensions

在Git Extensions中,用户在克隆存储库时,可以指定在生成的克隆中检出哪个分支(可能不是master)。

如何在命令行执行此操作?

1 个答案:

答案 0 :(得分:2)

答案通常在手册页中(在git-clone手册页中,在这里):

--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.

所以你想要运行

git clone --branch <name> <repository>

其中<name>代表您要在<repository>克隆中检出的分支的名称。


实施例

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