How do I fetch a branch on someone else's fork on GitHub? [duplicate]

风格不统一 提交于 2019-12-04 07:21:21

问题


I've forked from a repo on GitHub. I want to get the code from a branch on another user's fork.

Must I clone this user's whole repo to a separate local repo or can I do something like git checkout link_to_the_other_users_branch?


回答1:


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

Note that there are multiple "correct" URIs you can use for the remote when you add it in the first step.

  • git@github.com:theirusername/reponame.git is an SSH-based URI
  • https://github.com/theirusername/reponame.git is an HTTP URI

Which one you prefer to use will depend on your situation: GitHub has a help article explaining the difference and helping you choose: Which remote URL should I use?




回答2:


amalloy's suggestion didn't work for me. This did:

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

Resources:

  • https://git-scm.com/book/ch2-5.html
  • http://crunchify.com/how-to-fork-github-repository-create-pull-request-and-merge/


来源:https://stackoverflow.com/questions/9153598/how-do-i-fetch-a-branch-on-someone-elses-fork-on-github

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!