Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k 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 (50.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

Browse Categories

...