2016-09-14 101 views
3

我打算在github上添加一些基於項目的代碼,例如,添加一些適合我的項目的定製選項。維護與上游同步的分支

一個想法是分叉並創建一個分支來包含我所有的更改。每次上游有新的變化,我都會將它們重新分配給我的分支。

假設這些都是我的遙控器:

$ git remote -v 
my [email protected]:khing/myproject.git (fetch) 
my [email protected]:khing/pyproject.git (push) 
up https://github.com/upstream/project.git (fetch) 
up https://github.com/upstream/project.git (push) 

上游有三個提交:A,B,C,和我有兩個額外提交:M,N

所以我想目前的樹枝會像:

up: A--B--C 
my: A--B--C--M--N 

假設上游有兩個新的提交d和E,我應該獲取和重訂(是的,我可能要解決合併衝突),所以我想這將是:

up: A--B--C--D--E 
my: A--B--C--D--E--M--N 

這是維持我自己的分支,同時保持最新的上游分支的好方法嗎?

+0

抓取很好,但我不認爲你需要重新綁定。否則,這是很好的。這是要走的路。 –

回答

3

是的。這就是我在「Pull new updates from original GitHub repository into forked GitHub repository」中所描述的。

由於這個問題的答案(2010年),您可以:

  • 配置總是從原來的上游回購拉

    git remote set-url origin https://github.com/upstream/project.git 
    git remote set-url --push origin [email protected]:khing/myproject.git 
    
  • 確保你總是在頂部衍合本地提交什麼是牽強:
    (需要Git的2.9+六月2016年,看到 「Can 「git pull」 automatically stash and pop pending changes?」)

    git config pull.rebase true 
    git config rebase.autoStash true 
    

然後一個簡單的git pull就足夠了。

相關問題