git - 如何在GitHub上的别人的分支上获取分支?
这个问题在这里已有答案:
- 如何从其他人的回购中拉出远程分支 6个答案
我从GitHub的回购中分得一杯羹。 我想从另一个用户的分支中获取分支代码。
我必须将此用户的整个仓库克隆到单独的本地仓库,还是可以执行类似git checkout link_to_the_other_users_branch
的操作?
Christian asked 2019-07-05T17:51:22Z
2个解决方案
210 votes
$ git remote add theirusername git@github.com:theirusername/reponame.git
$ git fetch theirusername
$ git checkout -b mynamefortheirbranch theirusername/theirbranch
请注意,有多个"正确" 在第一步中添加遥控器时可以使用的URI。
https://github.com/theirusername/reponame.git
是基于SSH的URIhttps://github.com/theirusername/reponame.git
是HTTP URI
您更喜欢使用哪一个取决于您的情况:GitHub有一篇帮助文章解释差异并帮助您选择:我应该使用哪个远程URL?
19 votes
合金的建议对我没用。 这样做:
git remote add theirusername https://github.com/theirusername/reponame
git fetch theirusername
git checkout -b mynamefortheirbranch theirusername/theirbranch
资源:
- [https://git-scm.com/book/ch2-5.html]
- [http://crunchify.com/how-to-fork-github-repository-create-pull-request-and-merge/]