如何将现有的远程分支添加到本地克隆仓库中?

4
我想将此分支添加到我的本地克隆版本中:https://github.com/dmitriz/mithril.js/tree/rewrite。但由于某些原因,它并没有被克隆。因此,我只得到了不包含该分支的本地目录。有没有简单的方法也克隆这个分支呢?
3个回答

3

您只需要切换到这个分支即可。

$ git checkout rewrite

Git将切换到新的分支,并跟踪远程分支。您应该会收到以下消息。
Branch rewrite set up to track remote branch rewrite from origin.
Switched to a new branch 'rewrite'

3
无效: $ git checkout rewrite ---错误:路径规范“rewrite”与git已知的任何文件不匹配。 - Dmitri Zaitsev
应该可以,对我来说有效:https://gist.github.com/Richard-Degenne/76498f52de45f3a926f119a3c0c0ae7f - Richard-Degenne
我怀疑你的 Git 配置有问题,尽管我不知道具体是什么。 - Richard-Degenne
1
你说得对,我使用了Github客户端进行克隆,这显然是不可靠的。一旦从CL克隆,它就像你所描述的那样工作。 - Dmitri Zaitsev
我对了解是什么导致了这种行为很感兴趣。很高兴我的回答有所帮助。 - Richard-Degenne
显示剩余3条评论

1
我假设你最初克隆的存储库是你的origin
因此,只需执行git fetch origin,它应该出现在git branch -a上 - 之后,您可以使用git checkout -b rewrite origin/rewrite轻松检查它。
可能的解释是,在您最初克隆时该分支不存在,并且您从未获取过所有(新的)分支。

它没有出现,最后一个命令出现了错误:fatal: Cannot update paths and switch to branch 'rewrite' at the same time. Did you intend to checkout 'origin/rewrite' which can not be resolved as commit? - Dmitri Zaitsev

0
如果你克隆了一个版本库,你已经拥有了所有分支。你只需要从中创建一个本地分支,因为它是分布式源代码管理系统。
git checkout -b rewrite origin/rewrite

您还可以为本地分支指定其他名称或拥有多个副本。


无法工作:$ git checkout -b rewrite origin/rewrite致命错误:无法同时更新路径并切换到分支“rewrite”。您是否打算检出无法解析为提交的“origin/rewrite”? - Dmitri Zaitsev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接