保持与上游同步的分支维护

3
我计划基于Github上的一个项目添加一些代码,例如添加一些适合我的项目的自定义选项。
其中一个想法是fork并创建一个分支以包含所有我的更改。每次上游有新的更改时,我会将它们fetch并rebase到我的分支。
假设这些是我的远程仓库:
$ git remote -v
my   git@github.com:khing/myproject.git (fetch)
my   git@github.com:khing/pyproject.git (push)
up   https://github.com/upstream/project.git (fetch)
up   https://github.com/upstream/project.git (push)

upstream有三个提交: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

在与上游分支保持最新状态的同时维护自己的分支,这是一种好的方式吗?


Fetch很好,但我不认为你需要rebase。否则一切都很好。这是正确的方式。 - The Shooter
1个回答

3

是的。这就是我在 "从原始GitHub存储库拉取新更新到forked GitHub存储库" 中描述的内容。

自那个答案(2010年)以来,您可以:

  • configure to always pull from the original upstream repo

    git remote set-url origin https://github.com/upstream/project.git
    git remote set-url --push origin git@github.com:khing/myproject.git 
    
  • make sure you always rebase your local commits on top of what is fetched:
    (needs Git 2.9+, June 2016, see "Can “git pull” automatically stash and pop pending changes?")

    git config pull.rebase true
    git config rebase.autoStash true
    
然后只需要简单的git pull即可。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接