How do I check out a remote Git branch?

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

    Simply run git checkout with the name of the remote branch. Git will automatically create a local branch that tracks the remote one:

    git fetch
    git checkout test
    

    However, if that branch name is found in more than one remote, this won't work as Git doesn't know which to use. In that case you can use either:

    git checkout --track origin/test
    

    or

    git checkout -b test origin/test
    

    In 2.19, Git learned the checkout.defaultRemote configuration, which specifies a remote to default to when resolving such an ambiguity.

提交回复
热议问题