Git checkout: updating paths is incompatible with switching branches

后端 未结 11 701
你的背包
你的背包 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:14

    Not sure if this is helpful or exactly relevant to your question, but if you are trying to fetch and checkout only a single branch from the remote repository, then the following git commands will do the trick:

    url= << URL TO REPOSITORY >>
    branch= << BRANCH NAME >>
    
    git init
    git remote add origin $url
    git fetch origin $branch:origin/$branch
    git checkout -b $branch --track origin/$branch
    
    0 讨论(0)
  • 2020-11-27 09:14

    For me I had a typo and my remote branch didn't exist

    Use git branch -a to list remote branches

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

    none of the above worked for me. My situation is slightly different, my remote branch is not at origin. but in a different repository.

    git remote add remoterepo GIT_URL.git
    git fetch remoterepo
    git checkout -b branchname remoterepo/branchname
    

    tip: if you don't see the remote branch in the following output git branch -v -a there is no way to check it out.

    Confirmed working on 1.7.5.4

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

    I suspect there is no remote branch named remote-name, but that you've inadvertently created a local branch named origin/remote-name.

    Is it possible you at some point typed:

    git branch origin/remote-name
    

    Thus creating a local branch named origin/remote-name? Type this command:

    git checkout origin/remote-name
    

    You'll either see:

    Switched to branch "origin/remote-name"
    

    which means it's really a mis-named local branch, or

    Note: moving to "origin/rework-isscoring" which isn't a local branch
    If you want to create a new branch from this checkout, you may do so
    (now or later) by using -b with the checkout command again. Example:
      git checkout -b 
    

    which means it really is a remote branch.

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

    Alternate syntax,

    git fetch origin remote_branch_name:local_branch_name
    
    0 讨论(0)
  • 2020-11-27 09:24

    It's not very intuitive but this works well for me ...

      mkdir remote.git & cd remote.git & git init
      git remote add origin $REPO
      git fetch origin $BRANCH:refs/remotes/origin/$BRANCH        
    

    THEN run the git branch --track command ...

      git branch --track $BRANCH origin/$BRANCH
    
    0 讨论(0)
提交回复
热议问题