问题描述
我打算在github上添加一些基于项目的代码,例如添加一些适合我的项目的定制选项。
一个想法是分叉并创建一个分支来包含我所有的更改。每当上游有新的变化时,我都会将它们重新分配给我的分支。
假设这些是我的遥控器:
$ git remote -v
我的git@github.com:khing / myproject.git(fetch)
我的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
我:A - B - C - M - N
假设上游有两个新的提交D和E,我应该获取和重新绑定(是的,我可能不得不解决合并冲突),所以我猜测它会是:
up:A - B - C - D - E
my:A - B - C - D - E - M - N
这是维护我自己的分支并保持上游分支最新状态的好方法吗?
是的。这就是我在中所描述的内容。
从那个答案(2010)开始,您可以:
-
配置为始终从原始上游回购
git远程设定网址来源https://github.com/upstream/project.git
git remote set-url --push origin git@github.com:khing / myproject.git
-
(需要Git 2.9+,2016年6月,请参阅)git config pull.rebase true
git config rebase.autoStash true
然后一个简单的 git pull
就足够了。
I'm planning to add some code based on a project on github, e.g. add some customerized options that fit my project.
One idea is to fork and create a branch to include all my changes. Every time upstream has new changes, I fetch and rebase them to my branch.
Suppose these are my remotes:
$ 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 has three commits: A, B, C, and I have two extra commits: M, N
So I guess current branches will be like:
up: A--B--C
my: A--B--C--M--N
Suppose upstream has two new commits D and E, I should fetch and rebase (and yes, I might have to fix merge conflicts), so I guess it will be:
up: A--B--C--D--E
my: A--B--C--D--E--M--N
Is this a good way maintaining my own branch while keeping up-to-date with an upstream branch?
Yes. That is what I described in "Pull new updates from original GitHub repository into forked GitHub repository".
Since that answer (2010), you can:
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
Then a simple git pull
is enough.
这篇关于维护与上游同步的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!