维护与上游同步的分支 [英] Maintaining a branch that syncing with upstream

查看:88
本文介绍了维护与上游同步的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算在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

这是维护我自己的分支并保持上游分支最新状态的好方法吗?

解决方案

是的。这就是我在将原始GitHub存储库中的新更新引入分叉的GitHub存储库中所描述的内容。



从那个答案(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 pull 自动存储并弹出挂起的更改?

      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.

这篇关于维护与上游同步的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆