Git checkout: updating paths is incompatible with switching branches

后端 未结 11 702
你的背包
你的背包 2020-11-27 08:48

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/rem         


        
相关标签:
11条回答
  • 2020-11-27 09:26

    After fetching a zillion times still added remotes didn't show up, although the blobs were in the pool. Turns out the --tags option shouldn't be given to git remote add for whatever reason. You can manually remove it from the .git/config to make git fetch create the refs.

    0 讨论(0)
  • 2020-11-27 09:33

    For me what worked was:

    git fetch
    

    Which pulls all the refs down to your machine for all the branches on remote. Then I could do

    git checkout <branchname>
    

    and that worked perfectly. Similar to the top voted answer, but a little more simple.

    0 讨论(0)
  • 2020-11-27 09:35

    Could your issue be linked to this other SO question "checkout problem"?

    i.e.: a problem related to:

    • an old version of Git
    • a curious checkout syntax, which should be: git checkout -b [<new_branch>] [<start_point>], with [<start_point>] referring to the name of a commit at which to start the new branch, and 'origin/remote-name' is not that.
      (whereas git branch does support a start_point being the name of a remote branch)

    Note: what the checkout.sh script says is:

      if test '' != "$newbranch$force$merge"
      then
        die "git checkout: updating paths is incompatible with switching branches/forcing$hint"
      fi
    

    It is like the syntax git checkout -b [] [remote_branch_name] was both renaming the branch and resetting the new starting point of the new branch, which is deemed incompatible.

    0 讨论(0)
  • 2020-11-27 09:36

    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
    
    0 讨论(0)
  • 2020-11-27 09:38

    After having tried most of what I could read in this thread without success, I stumbled across this one: Remote branch not showing up in "git branch -r"

    It turned out that my .git/config file was incorrect. After doing a simple fix all branches showed up.

    Going from

    [remote "origin"]
        url = http://stash.server.com/scm/EX/project.git
        fetch = +refs/heads/master:refs/remotes/origin/master
    

    to

    [remote "origin"]
        url = http://stash.server.com/scm/EX/project.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    

    Did the trick

    0 讨论(0)
提交回复
热议问题