远程存储库包含各种分支,如origin/davis_branch:
$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/master
如何将daves_branch获取到本地存储库,以便它跟踪origin/davis_branch?
我尝试了:
$ git fetch origin discover
$ git checkout discover
远程存储库包含各种分支,如origin/davis_branch:
$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/master
如何将daves_branch获取到本地存储库,以便它跟踪origin/davis_branch?
我尝试了:
$ git fetch origin discover
$ git checkout discover
当前回答
假设你的遥控器git@xyz.git你想要它的random_branch分支。流程应如下:
首先检查遥控器列表git远程-v如果你没有git@xyz.git在上述命令的输出中,您可以通过git远程添加xyzgit@xyz.git现在,您可以通过git获取xyz现在通过git checkout-b my_copy_random_branch xyz/random_brance检查分支列表查看所有的分支
本地分支my_copy_random_branch将跟踪远程的random_brance分支。
其他回答
如果要获取所有远程分支,请键入:
git fetch --all
您也可以一次获取并签出远程分支:
git fetch && git checkout the-branch-name
在我看来,这一行命令是获取和签出本地不存在的远程分支的最简单方法:git获取和git签出remote_branch
要签出远程而非本地存在的myBranch,这对我很有用:
git fetch --all
git checkout myBranch
我收到了这条消息:
Branch myBranch set up to track remote branch myBranch from origin
Switched to a new branch 'myBranch'
git checkout -b branch_name
git pull remote_name branch_name