Can not create a local and remote branch (tracking) at the same time

匿名 (未验证) 提交于 2019-12-03 08:35:02

问题:

From Pro Git:

you can set up other tracking branches if you wish ― ones that don’t track branches on origin and don’t track the master branch. The simple case is the example you just saw, running git checkout -b [branch] [remotename]/[branch]

$ git checkout --track origin/serverfix Branch serverfix set up to track remote branch refs/remotes/origin/serverfix. Switched to a new branch "serverfix"

$ git checkout -b sf origin/serverfix Branch sf set up to track remote branch refs/remotes/origin/serverfix. Switched to a new branch "sf"

My understanding is that this presents a way to create a local branch and an upstream branch.

But when I do:

git checkout -b iss53 origin/iss53 I get:
fatal: Cannot update paths and switch to branch 'iss53' at the same time.

And when I do:
git checkout --track origin/iss53 I get:

fatal: Cannot update paths and switch to branch 'iss53' at the same time. Did you intend to checkout 'origin/iss53' which can not be resolved as commit?

Why?

回答1:

Cannot update paths and switch to branch 

As I mention in "Get new upstream branch with git", you can try:

# let's create a new local branch first git checkout -b iss53 # then reset its starting point git reset --hard origin/iss53  

Make sure that the remote tracking branch origin/iss53 does exist first (after a git fetch origin)

origin/iss53 means there was a iss53 on the upstream remote repo referenced by origin.

If there was not such a branch, then you only create a local branch iss53, and push it like so:

git push -u origin iss53  

That would establish an association between the local branch iss53 and the remote tracking branch origin/iss53 (tracking the newly created branch iss53 on origin, created by the push).

See "Why do I need to explicitly push a new branch?" for more on that initial push.



回答2:

Seems like you hadn't fetch that commit yet. So, first do:

git fetch origin 

And then:

git checkout --track origin/iss53 


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