views:

5637

answers:

5

My problem is related to:

http://stackoverflow.com/questions/180064/fatal-git-error-when-switching-branch

I try to fetch a remote branch with the command

git checkout -b local-name origin/remote-name

but I get this error message:

fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/remote-name' which can not be resolved as commit?

If I mannually create a branch, and then pull the remote branch, it does work, just as makeing a new clone and checking the branch out.

But I want to know why it does not work on the repository I work with.

+1  A: 

I don't know why, or how, but this seemed to have solved my problem.

Some (seemly) arbitrary commands seem to solve the problem:

git checkout -f master
git pull
git checkout --track -b

Although you get some error messages, it does work.

Ikke
You should edit this post to include what that page described as the answer and then accept this as the answer. That way if that site dies someone can still find the answer here. Also that would take it out of the list of unanswered questions.
docgnome
A: 

Could your issue be linked to this other SO question "checkout problem"?

i.e.: a problem related to:

  • an old version of Git
  • a curious checkout syntax, which should be: git checkout -b [<new_branch>] [<start_point>], with [<start_point>] referring to the name of a commit at which to start the new branch, and 'origin/remote-name' is not that.
    (whereas git branch does support a start_point being the name of a remote branch)

Note: what the checkout.sh script says is:

  if test '' != "$newbranch$force$merge"
  then
    die "git checkout: updating paths is incompatible with switching branches/forcing$hint"
  fi

It is like the syntax git checkout -b [] [remote_branch_name] was both renaming the branch and resetting the new starting point of the new branch, which is deemed incompatible.

VonC
The problem is solved. git checkout -b local-name remote/remote-branch does actually work
Ikke
Interesting, what has changed since the first instance of that command (triggering the error message) ?
VonC
+29  A: 

I believe this occurs when you are trying to checkout a remote branch that your local git repo is not aware of yet. Try:

git remote show origin

If the remote branch you want to checkout is under "New remote branches" and not "Tracked remote branches" then you need to fetch them first:

git fetch

Now it should work:

git checkout -b local-name origin/remote-name
This solved the problem for me, not the above arbitrary answer.
Jessedc
That should be "git fetch REPOSITORY_NAME" to get all of the branches on that repository.
Mike Thomsen
not necessarily. `git fetch` will get all of the branches from all remote repos.
Michael Grinich
+2  A: 

alternate syntax

git fetch origin remote_branch_name:local_branch_name

http://github.com/guides/showing-and-tracking-remote-branches

Rare Pleasures
A: 

I suspect there is no remote branch named remote-name, but that you've inadvertantly created a local branch named origin/remote-name.

Is it possible you at some point typed:

git branch origin/remote-name

Thus creating a local branch named origin/remote-name? Type this command:

git checkout origin/remote-name

You'll either see:

Switched to branch "origin/remote-name"

which means it's really a mis-named local branch, or

Note: moving to "origin/rework-isscoring" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b 

which means it really is a remote branch.

Don Branson