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?
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.
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.
Alternate syntax,
git fetch origin remote_branch_name:local_branch_name
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With