2012-02-05 133 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

相關問題