由于您使用了--single-branch
选项克隆仓库,因此它只跟踪远程仓库的这个分支。
简而言之:要完全撤销--single-branch
,请撤销其配置设置并重新获取。
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch
在使用
--single-branch
参数创建仓库后,如果想要从远程仓库获取其他分支,需要显式地执行
fetch
操作。
git fetch origin +refs/heads/<branch-name>:refs/remotes/origin/<branch-name>
或者,您可以通过将<branch-name>
替换为*
来获取所有远程分支。
现在您应该能够检出新拉取的分支。
git checkout <branch-name>
解释
我使用的fetch语法可以大致描述为source:target
。
在使用它时,您将使用第一个路径描述fetch的source
,同时使用第二个路径确定target
。
这意味着您正在从refs/heads/<branch>
获取远程分支,并将结果写入refs/remotes/origin/<branch>
。当然,也可以将其写入其他位置,例如仅本地分支,使用<branch>
(名称也可以随意选择)。
此外,这就解释了为什么git push origin :<branch>
会删除远程的<branch>
,因为您正在将nothing推送到远程分支,从而有效地删除它。
注意:在编写refs/heads/<branch>
时,refs/heads/
是完全可选的,如果您只声明<branch>
,git将查找refs/heads/
。这不仅适用于获取,而且适用于所有分支引用。
git remote add new u://r/l; git fetch new
。 - jthill