How do I check out a remote Git branch?

后端 未结 30 2449
灰色年华
灰色年华 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:33

    I was stuck in a situation seeing error: pathspec 'desired-branch' did not match any file(s) known to git. for all of the suggestions above. I'm on git version 1.8.3.1.

    So this worked for me:

    git fetch origin desired-branch
    git checkout -b desired-branch FETCH_HEAD
    

    The explanation behind is that I've noticed that when fetching the remote branch, it was fetched to FETCH_HEAD:

    $ git fetch origin desired-branch
    From github.com:MYTEAM/my-repo
        * branch            desired-branch -> FETCH_HEAD
    

提交回复
热议问题