问题
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
回答3:
FWIW for other people with the same error message: when this happened to me, the underlying problem was that I was trying to make a branch with spaces in the name. For the set of pre-canned GIT commands I had, branches with spaces were a problem.
(ObDisclaimer: I am very, very far from a git expert. I just know that I had a problem with an identical error message, and the solution was different than the accepted answer)
来源:https://stackoverflow.com/questions/17137441/can-not-create-a-local-and-remote-branch-tracking-at-the-same-time