简体   繁体   English

维护与上游同步的分支

[英]Maintaining a branch that syncing with upstream

I'm planning to add some code based on a project on github, eg add some customerized options that fit my project. 我打算在github上添加一些基于项目的代码,例如添加一些适合我项目的自定义选项。

One idea is to fork and create a branch to include all my changes. 一个想法是fork并创建一个分支以包含我的所有更改。 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 上游有三个提交:A,B,C,我有两个额外的提交: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: 假设上游有两个新的提交D和E,我应该获取和rebase(是的,我可能必须修复合并冲突),所以我猜它会是:

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 ". 这就是我在“将原始GitHub存储库中的新更新拉入分叉GitHub存储库 ”中所描述的内容。

Since that answer (2010), you can: 从那个答案(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 2.9 +,2016年6月,请参阅“ 可以” git pull “自动存储并弹出挂起的更改? ”)

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

Then a simple git pull is enough. 那么简单的git pull就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM