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 [email protected]:khing/myproject.git (fetch)
my [email protected]: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 [email protected]: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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With