0 votes
1 view
in DevOps and Agile by (30k points)

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?

1 Answer

0 votes
by (51.2k points)

This error occurs when you are trying to check out a remote branch that your local git repo is not aware of. Try: 

git remote show origin

After running this command if the remote branch is under a new branch and not tracked you need to fetch it using:

git remote update

git fetch

After this, your remote branch is known to the local git repo so now your command will work.

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

Refer: https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutemltbranchgt

Welcome to Intellipaat Community. Get your technical queries answered by top developers !