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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9153598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:54:38  来源:igfitidea点击:

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

gitgithubgit-branchgit-forkgit-fetch

提问by Christian

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

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

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?

我必须将这个用户的整个 repo 克隆到一个单独的本地 repo 或者我可以做类似的事情git checkout link_to_the_other_users_branch吗?

回答by amalloy

$ git remote add theirusername [email protected]: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.

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

  • [email protected]:theirusername/reponame.gitis an SSH-based URI
  • https://github.com/theirusername/reponame.gitis an HTTP URI
  • [email protected]:theirusername/reponame.git是基于 SSH 的 URI
  • https://github.com/theirusername/reponame.git是一个 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?

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

回答by Mateusz Piotrowski

amalloy's suggestiondidn't work for me. This did:

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

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

Resources:

资源: