标签云

微信群

扫码加入我们

WeChat QR Code

My problem is related to 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 manually create a branch and then pull the remote branch, it works, just as making a new clone and checking the branch out.

Why does it not work on the repository I work with?


what has changed since the first instance of that command (triggering the error message) ?

2018年08月16日26分13秒

git init git fetch git fetch git://blabla.com/dir1/Project.git

2018年08月15日26分13秒

This solved the problem for me, not the above arbitrary answer.

2018年08月16日26分13秒

That should be "git fetch REPOSITORY_NAME" to get all of the branches on that repository.

2018年08月16日26分13秒

not necessarily. git fetch will get all of the branches from all remote repos.

2018年08月15日26分13秒

In case anyone else struggles with the utter craziness of all this: git fetch origin/branchname Is not the same as git fetch. The former simply results in "new (next fetch will store in remotes/origin)" displaying in a column visible via git remote show origin.

2018年08月16日26分13秒

If you are trying to do this for a remote that you explicitly added (so anything other than origin) you will need to do git remote update before your fetch will fetch that remote. Otherwise you get messages like Did you intend to checkout 'upstream-repo/master' which can not be resolved as commit? Please add this to the answer and save people hours worth of reading the same answers that only work for origin.

2018年08月16日26分13秒

This worked for me. My remote branch name isn't origin. I don't know if that makes a difference as I have been drinking vodka.

2018年08月16日26分13秒

This is not just an alternate syntax, but can work when git checkout -b branch_name origin/branch_name does not work

2018年08月16日26分13秒

This also fixed my problem when running "git checkout --track origin/remote-branch", which originally gave the same error as OP's before the fix. Thanks!

2018年08月16日26分13秒

Worked for me after running also the validated answer.

2018年08月15日26分13秒

Yes, I suspect the --depth qualifier for the original clone may be at fault here. I had success with git fetch remote_branch_name:local_branch_name but all other advice failed.

2018年08月15日26分13秒

That's indeed an odd configuration. It tells git to only fetch the master branch from the remote.

2018年08月16日26分13秒

I would vote it up 10 times if I could! - this seems to be some thing that new git does when cloning

2018年08月16日26分13秒

I had the same problem, it was driving me crazy. Anyone not seeing remote branches, please check this!!

2018年08月16日26分13秒

Thank god for your answer :)

2018年08月16日26分13秒

arf, just realize VirtualStaticVoid had the same solution!

2018年08月15日26分13秒

+1 for git branch -v -a: I had an incorrectly configured remote that said fetch = +refs/heads/*:refs/remotes/master/* even though the remote was called upstream.

2018年08月16日26分13秒

It works,Thank you

2018年08月16日26分13秒

The problem is solved. git checkout -b local-name remote/remote-branch does actually work

2018年08月15日26分13秒

Interesting, what has changed since the first instance of that command (triggering the error message) ?

2018年08月16日26分13秒