远程存储库包含各种分支,如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 fetch origin
git checkout --track origin/<remote_branch_name>
这假设您要从原点提取。如果没有,请用远程名称替换源。
其他回答
只需尝试:
git pull origin your_branch_name
要签出远程而非本地存在的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 fetch origin
git checkout --track origin/<remote_branch_name>
这假设您要从原点提取。如果没有,请用远程名称替换源。
使用gitbranch-a(本地和远程分支)或gitbranch-r(仅远程分支)查看所有远程及其分支。然后,您可以对远程执行git checkout-t remotes/repo/branch并创建本地分支。
还有一个git-ls-remote命令,用于查看该远程的所有ref和标记。
git checkout -b branch_name
git pull remote_name branch_name