从 git 中拉出特定分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20033863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pull specific branch from git
提问by Shiva Krishna Bavandla
I have a repo in bitbucket
, and i am using git
.
我有一个 repo bitbucket
,我正在使用git
.
So my branches are
所以我的分支是
master
develop_one
develop_two
When i use git clone [email protected]: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 ?
当我使用时git clone [email protected]:project/project.git
,我只得到主分支代码,但我只需要克隆/拉取develop_one
分支,那么如何只克隆/拉取develop_one
分支代码?
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
注意:其他分支(develop_one、develop_two)没有合并到master中,在功能真正完成之前不想合并,所以只想get/clone/pull一个特定的分支代码
回答by tombruijn
Try:
尝试:
git clone [email protected]:project/project.git -b develop_one --single-branch
git clone [email protected]: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.
这将从远程跟踪 develop_one 分支。
回答by eulerworks
Also, to add to @tomrbrujin 's answer, you can specify the name of the local destination directory in the clonecommand like this:
此外,要添加到@tomrbrujin 的答案中,您可以在clone命令中指定本地目标目录的名称,如下所示:
git clone https://github.com/example/example1.git -b branch_name --single-branch local_name
The final arg passed, local_namewould create and name the local copy of the cloned remote directory "local_name."
最后一个参数通过,local_name将创建并命名克隆远程目录的本地副本“local_name”。
Otherwise, the local directory name will only reflect the repo name, which here would be: example
否则,本地目录名称将仅反映 repo 名称,此处为:example