3

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?

Deqing
  • 14,098
  • 15
  • 84
  • 131

1 Answers1

3

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250