12

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?

Jim
  • 18,826
  • 34
  • 135
  • 254

3 Answers3

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • But how do I create `origin/iss53` in the first place? – Jim Jun 16 '13 at 21:10
  • The hint to get from "upstream" rather than "origin" in the referenced answer (http://stackoverflow.com/questions/15730551/get-new-upstream-branch-with-git/15731197#15731197) was what I was missing. – Hector Correa Sep 16 '14 at 14:08
  • when I go git reset --hard upstream/origin I get: fatal: ambiguous argument 'upstream/master': unknown revision or path not in the working tree This is after I git fetch upstream master – sureshvv Apr 12 '15 at 07:51
  • @sureshvv could you make that a new question with details about your repo config? – VonC Apr 12 '15 at 10:15
  • @VonC: I meant to say git reset --hard upstream/master. – sureshvv Apr 14 '15 at 11:30
  • @sureshvv ok: can you make a separate question, with a bit more details? – VonC Apr 14 '15 at 11:32
4

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

git fetch origin

And then:

git checkout --track origin/iss53
Diego V
  • 6,189
  • 7
  • 40
  • 45
0

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)

PESMITH_MSFT
  • 350
  • 1
  • 9