如何在GitHub上的其他人的分支上获取分支?

Chr*_*ian 127 git github git-fetch git-branch git-fork

我从GitHub上的回购中分得一杯羹.我想从另一个用户的fork上的分支获取代码.

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

ama*_*loy 229

$ git remote add theirusername git@github.com:theirusername/reponame.git
$ git fetch theirusername
$ git checkout -b mynamefortheirbranch theirusername/theirbranch
Run Code Online (Sandbox Code Playgroud)

请注意,在第一步中添加遥控器时,可以使用多个"正确"的URI.

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

您更喜欢使用哪一个取决于您的情况:GitHub有一篇帮助文章解释了差异并帮助您选择:我应该使用哪个远程URL?

  • 我得到*致命:无法更新路径并同时切换到分支'xyz'.您是否打算结帐"xyz/xyz",无法解析为提交?* (3认同)
  • 最后一行检查一个名为`mynamefortheirbranch`的新分支,其起始点设置为`hisusername/theirbranch`的头部. (2认同)
  • 没和我一起工作。 (2认同)

Mat*_*ski 23

amalloy的建议对我不起作用.这样做:

git remote add theirusername https://github.com/theirusername/reponame
git fetch theirusername
git checkout -b mynamefortheirbranch theirusername/theirbranch
Run Code Online (Sandbox Code Playgroud)

资源: