我打算根据 github 上的项目添加一些代码,例如添加一些适合我的项目的定制选项。
一个想法是 fork 并创建一个分支以包含我的所有更改。每当上游有新的更改时,我都会获取它们并将其 rebase 到我的分支。
假设这些是我的 Remote :
$ 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)
上游有三个提交:A、B、C,我有两个额外的提交:M、N
所以我猜当前的分支会是这样的:
up: A--B--C
my: A--B--C--M--N
假设上游有两个新的提交 D 和 E,我应该获取和 rebase (是的,我可能必须修复 merge 冲突),所以我猜它会是:
up: A--B--C--D--E
my: A--B--C--D--E--M--N
这是维护我自己的分支同时与上游分支保持同步的好方法吗?
最佳答案
是的。这就是我在“Pull new updates from original GitHub repository into forked GitHub repository”中描述的内容。
自该答案(2010 年)以来,您可以:
配置为始终从原始上游仓库 pull
git remote set-url origin https://github.com/upstream/project.git git remote set-url --push origin git@github.com:khing/myproject.git
确保始终在获取的内容之上重新设置本地提交的基数:
(需要 Git 2.9+,2016 年 6 月,参见“Can “git pull
” automatically stash and pop pending changes?”)git config pull.rebase true git config rebase.autoStash true
那么一个简单的 git pull
就足够了。
关于git - 维护一个与上游同步的分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39483034/