【问题标题】:How do I fetch a branch on someone else's fork on GitHub? [duplicate]如何在 GitHub 上获取别人的 fork 上的分支? [复制]
【发布时间】:2012-02-27 13:02:38
【问题描述】:

我从 GitHub 上的一个 repo 分叉出来。我想从另一个用户的分支上的分支获取代码。

我必须将此用户的整个 repo 克隆到单独的本地 repo 还是可以执行 git checkout link_to_the_other_users_branch 之类的操作?

【问题讨论】:

标签: git github git-branch git-fork git-fetch


【解决方案1】:
$ git remote add theirusername git@github.com:theirusername/reponame.git
$ git fetch theirusername
$ git checkout -b mynamefortheirbranch theirusername/theirbranch

请注意,当您在第一步中添加远程时,您可以将多个“正确”URI 用于远程。

  • git@github.com:theirusername/reponame.git 是一个基于 SSH 的 URI
  • https://github.com/theirusername/reponame.git 是一个 HTTP URI

您更喜欢使用哪一种取决于您的情况。 GitHub有帮助文章解释区别并帮助你选择:Which remote URL should I use?

【讨论】:

  • 最后一行是做什么的?
  • 最后一行检查出一个名为mynamefortheirbranch 的新分支,其起点设置为theirusername/theirbranch 的头部。
  • 我得到 致命错误:无法更新路径并同时切换到分支“xyz”。您是否打算签出无法解析为提交的“xyz/xyz”?
  • 不适合我。
  • @amalloy 它正在按预期创建一个分支,但不允许在我当前的分支中推送分支。收到此消息“要推送到远程的上游分支,请使用 git push krupa-fork HEAD:develop 要推送到远程的同名分支,请使用 git push krupa-fork HEAD”
【解决方案2】:

amalloy's suggestion 对我不起作用。这样做了:

git remote add theirusername https://github.com/theirusername/reponame
git fetch theirusername
git checkout -b mynamefortheirbranch theirusername/theirbranch

资源:

【讨论】:

  • 我相信您在第一行末尾缺少.git
  • @TomNorway 你确定吗?这样的你不适合吗?
  • @TomNorway 我测试了它,它在没有.git 扩展名的情况下工作。你用 GitHub 吗?
  • 确实如此。我必须承认我没有测试它——我的错误。我只用 .git 进行了测试,我认为这是必需的。
  • @MateuszPiotrowski 是的,好吧,我错误地使用了第一个命令(添加后错过了他们的用户名)。对不起:)
猜你喜欢
  • 1970-01-01
  • 2011-05-23
  • 2020-06-03
  • 2015-09-14
  • 2019-02-02
  • 2013-04-30
  • 2012-04-03
  • 2019-10-03
  • 2021-09-25
相关资源
最近更新 更多