Git checkout -b, 分支已经存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27281741/
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
Git checkout -b, branch already exists
提问by okay56k
When I'm merging two branches and they can't be merged automatically Github provides these instructions:
当我合并两个分支并且它们不能自动合并时,Github 提供了以下说明:
Step 1: From your project repository, bring in the changes and test.
第 1 步:从您的项目存储库中,引入更改并进行测试。
git fetch origin
git checkout -b master origin/master
git merge develop
Step 2: Merge the changes and update on GitHub.
第 2 步:在 GitHub 上合并更改和更新。
git checkout develop
git merge --no-ff master
git push origin develop
But, in this case, the branch master
already exists locally, and the line git checkout -b master origin/master
returns this message:
但是,在这种情况下,该分支master
已在本地存在,并且该行git checkout -b master origin/master
返回此消息:
git checkout -b master origin/master
fatal: A branch named 'master' already exists.
Is the correct thing to do in this case to replace that line with git checkout master
? I've wondered this for a while, bit worried about what git checkout master
might do as opposed to with -b
.
在这种情况下,用 替换该行是否正确git checkout master
?我已经想了一段时间了,有点担心git checkout master
与-b
.
回答by Ismail Badawi
If master
doesn't exist, then after this line
如果master
不存在,则在此行之后
git checkout -b master origin/master
master
will be a branch pointing to the same commit as origin/master
.
master
将是一个指向与origin/master
.
If you already have a master
branch, it might be out of date with origin/master
, so simply writing
如果你已经有一个master
分支,它可能已经过时了origin/master
,所以简单地写
git checkout master
isn't quite enough. You'll also want to run
还不够。你也想跑
git merge origin/master
afterward to bring master
up to date (typically this will just be a fast forward).
之后master
更新(通常这只是一个快进)。