At the university where I work, we use an open source learning management system (Moodle). Over time, we've edited the source code directly to fix bugs we've found and provide custom functionality. I'd like to be able to keep up with the bug fixes via a Git repository while also keeping track of our changes and making sure that our edits are preserved.

I'm a relative Git newbie, but from what I can tell here is our current situation.

     --C----C----C----C----C   < custom
---B-----F-----F-----F-----F-----F-----F--...   < origin

B = the build we installed
C = our changes
F = bug fixes

My question, to make it short, is how to combine the C's and F's together. Merging? Rebasing? Which tree should I merge/rebase into the other?

  • I'm not saying that the question is not valid for SU, but if you ask it on Stack Overflow you'll find many more Git users, I suspect.
    – CarlF
    Jan 26, 2010 at 19:26
  • whitequark's answer works great. I can even see only the changes in the custom branch by running git log --first-parent Feb 24, 2010 at 23:39
  • Note that it is often beneficial for all parties if bug fixes goes upstream, not least for this very reason: keeping a local branch up-to-date can require unnecessary work. When files start to diverge, things get hairy. Sep 9, 2013 at 12:43

1 Answer 1


Merging and rebasing are basically doing the same: making the last commit incorporate changes from both provided branches. But the way them do it is different.

Merging creates a commit that has two specified as parents, and rebasing 'moves' your tree so it's first commit is based (i.e. has one parent) on last commit of other branch (origin in your case). Resulting tree state is identical.

The right thing to do in this case is merge custom branch with origin:

git checkout custom
git merge origin

Rebasing is only useful if you want to send a bunch of patches to maintainer of projects so he doesn't need to adapt them to more recent changes manually.

Rebasing commands would be:

git checkout custom
git rebase origin

Also there is a git-cherry-pick(1) command that can be used to apply an arbitrary commit from any branch as a patch would be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.