How do I check out a remote Git branch?

后端 未结 30 1995
灰色年华
灰色年华 2020-11-22 00:12

Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.

<
30条回答
  •  不知归路
    2020-11-22 00:45

    For us, it seems the remote.origin.fetch configuration gave a problem. Therefore, we could not see any other remote branches than master, so git fetch [--all] did not help. Neither git checkout mybranch nor git checkout -b mybranch --track origin/mybranch did work, although it certainly was at remote.

    The previous configuration only allowed master to be fetched:

    $ git config --list | grep fetch
    remote.origin.fetch=+refs/heads/master:refs/remotes/origin/master
    

    Fix it by using * and fetch the new information from origin:

    $ git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
    
    $ git fetch
    ...
     * [new branch] ...
    ...
    

    Now we could git checkout the remote branch locally.

    No idea how this config ended up in our local repo.

提交回复
热议问题