远程存储库包含各种分支,如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 remote
=> One
=> Two
并且您知道要签出的分支名称,例如br1.2.3.4,然后执行
git fetch One
=> returns all meta data of remote, that is, the branch name in question.
剩下的就是结账
git checkout br.1.2.3.4
然后用它做新的树枝。
其他回答
git fetch
git branch -r
git checkout <branch_name>
如果您正在尝试“签出”一个新的远程分支(仅存在于远程,而不存在于本地),以下是您需要的:
git fetch origin
git checkout --track origin/<remote_branch_name>
这假设您要从原点提取。如果没有,请用远程名称替换源。
帮助我的是
1) 查看所有可用的远程分支(例如“远程分支名称”)
git branch -r
2) 使用远程分支名称创建本地分支
git fetch && git checkout 'remote-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'