2011-11-19 275 views
3

我從git:如何從遠程分支獲取併合併到本地分支?

從那裏我會克隆,並結賬導致

  • github.com/MYACCOUNT/ mantisbt

分叉該分行(我感興趣的是我n)到我的本地機器。

我的問題是,我想從遠程存儲庫(mantisbt/mantisbt)中獲取最新的分支(master-1.2.x),並將其合併到本地存儲庫的同一分支下。

這將導致類似

  • 混帳取遠程回購分支
  • 混帳合併遠程回購分支/本地分支

這是怎麼回事做了什麼?

UPDATE:

內容被取出與

  • GIT中取上游主1.2.x的

和合併到當前已簽出分支

  • git merge origin/master-1.2.x
+0

可能重複[Git:在本地合併遠程分支](https://stackoverflow.com/questions/21651185/git-merge-a-remote-branch-locally) –

回答

7

Github在他們的"fork a repo" help documentation中有一個例子。

git remote add upstream git://github.com/mantisbt/mantisbt 
// Assigns the original repo to a remote called "upstream" 
git fetch upstream 
+0

我試過(之前問這裏),但當你克隆時,只有主分支被「獲取」和「合併」「創建」和「更新」。分支機構不受影響,並在遠程回購分叉時保留在修訂版本中。 – udo

+0

您只需指定要拉取的上游分支的名稱即可。對此,還有其他一些問題。 http://stackoverflow.com/questions/67699/how-do-i-clone-all-remote-branches-with-git http://stackoverflow.com/questions/1709177/git-pull-certain-branch-from -github。基本上'git獲取上游其他分支' – ptomli

0

什麼只是沒有工作對我來說(GIT版本1.7.9.5,並使用HTTPS協議):

本來我分叉從 「帳戶」, 「foobar.git」 到 「我的賬戶」:

their_account/foobar.git => my_account/foobar.git 

感興趣的分支是「巴茲」

我的工作和「巴茲」造提交他們這樣做了。我想合併他們的提交與我的。作爲ptomli上述建議的,我所做的:

$ git checkout baz 
$ git fetch https://github.com/their_account/foobar.git baz 
Username for 'https://github.com': my_account 
Password for 'https://[email protected]': 
remote: Counting objects: 189, done. 
remote: Compressing objects: 100% (109/109), done. 
remote: Total 189 (delta 92), reused 151 (delta 76) 
Receiving objects: 100% (189/189), 107.77 KiB, done. 
Resolving deltas: 100% (92/92), done. 
From https://github.com/their_account/foobar 
* branch   baz -> FETCH_HEAD 

,我沒有看到提到了步驟:

$ git merge FETCH_HEAD 

和兩個分支合併。