Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git checkout: updating paths is incompatible with switching branches

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?

like image 770
Ikke Avatar asked Jun 03 '09 16:06

Ikke


People also ask

How do you switch branches?

The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

What is git switch?

The "switch" command allows you to switch your current HEAD branch. It's relatively new (added in Git v2. 23) and provides a simpler alternative to the classic "checkout" command. Before "switch" was available, changing branches had to be done with the "checkout" command.


2 Answers

Alternate syntax,

git fetch origin remote_branch_name:local_branch_name 
like image 24
Rare Pleasures Avatar answered Sep 19 '22 16:09

Rare Pleasures


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 remote update git fetch 

Now it should work:

git checkout -b local-name origin/remote-name 
like image 115
user167628 Avatar answered Sep 20 '22 16:09

user167628