165

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

我必须将此用户的整个存储库克隆到单独的本地存储库还是可以做类似的事情git checkout link_to_the_other_users_branch

4

2 回答 2

307
$ 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 有一篇帮助文章解释了区别并帮助您选择:我应该使用哪个远程 URL?

于 2012-02-05T22:35:37.923 回答
34

amalloy 的建议对我不起作用。这做到了:

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

资源:

于 2016-06-07T18:34:26.367 回答