2012-02-05 137 views
82

我已经从GitHub上的回购分支中分出。我想从另一个用户的分支上的分支获取代码。如何在GitHub上的其他人的分支上获取分支?

我必须将此用户的整个回购单复制到单独的本地回购单,还是可以执行类似git checkout link_to_the_other_users_branch的活动?

+1

你要找的git的 “遥控器”:http://progit.org/book/ch2- 5.html – millimoose 2012-02-05 22:20:37

回答

146
$ git remote add theirusername [email protected]:theirusername/reponame.git 
$ git fetch theirusername 
$ git checkout -b mynamefortheirbranch theirusername/theirbranch 

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

  • [email protected]:theirusername/reponame.git是SSH,基于URI
  • https://github.com/theirusername/reponame.git是一个HTTP URI

你更喜欢哪一个使用将取决于您的情况:GitHub上有一个帮助的文章,解释的差异,并帮助您选择:Which remote URL should I use?

+0

最后一行是做什么的? – 2015-07-10 15:43:20

+2

最后一行检出一个名为'mynamefortheirbranch'的新分支,其起点设置为'theirusername/theirbranch'的头部。 – 2015-07-15 01:16:25

+2

我得到*致命:不能更新路径并同时切换到分支'xyz'。您是否打算结账'xyz/xyz',无法解析为提交?* – 2015-11-03 18:39:04

11

amalloy's suggestion不适合我。该做的:

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

资源:

+0

我相信你在第一行结尾缺少'.git'。 – TomNorway 2016-10-13 17:05:30

+0

@TomNorway你确定吗?这不适合你吗? – 2016-10-13 17:07:10

+0

@TomNorway我测试了它,它没有'.git'扩展名。你使用GitHub吗? – 2016-10-13 17:09:26

相关问题