远程存储库包含各种分支,如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
当前回答
使用gitbranch-a(本地和远程分支)或gitbranch-r(仅远程分支)查看所有远程及其分支。然后,您可以对远程执行git checkout-t remotes/repo/branch并创建本地分支。
还有一个git-ls-remote命令,用于查看该远程的所有ref和标记。
其他回答
假设你的遥控器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分支。
如果您有一个使用--depth 1克隆的存储库,那么列出的许多命令将无法工作。例如,请参见此处
% git clone --depth 1 https://github.com/repo/code
Cloning into 'code'...
cd code
remote: Counting objects: 1778, done.
remote: Compressing objects: 100% (1105/1105), done.
remote: Total 1778 (delta 87), reused 1390 (delta 58), pack-reused 0
Receiving objects: 100% (1778/1778), 5.54 MiB | 4.33 MiB/s, done.
Resolving deltas: 100% (87/87), done.
Checking connectivity... done.
Checking out files: 100% (1215/1215), done.
% cd code
% git checkout other_branch
error: pathspec 'other_branch' did not match any file(s) known to git.
% git fetch origin other_branch
remote: Counting objects: 47289, done.
remote: Compressing objects: 100% (15906/15906), done.
remote: Total 47289 (delta 30151), reused 46699 (delta 29570), pack-reused 0
Receiving objects: 100% (47289/47289), 31.03 MiB | 5.70 MiB/s, done.
Resolving deltas: 100% (30151/30151), completed with 362 local objects.
From https://github.com/repo/code
* branch other_branch-> FETCH_HEAD
% git checkout other_branch
error: pathspec 'other_branch' did not match any file(s) known to git.
%
在这种情况下,我会重新克隆存储库,但可能还有其他技术,例如git浅层克隆(clone--depth)错过了远程分支
git fetch
git branch -r
git checkout <branch_name>
如果您正在尝试“签出”一个新的远程分支(仅存在于远程,而不存在于本地),以下是您需要的:
git fetch origin
git checkout --track origin/<remote_branch_name>
这假设您要从原点提取。如果没有,请用远程名称替换源。
git fetch&&git checkout<你朋友的分行名>应该可以做到这一点