Merge and Rebase

Screen Shot 2013-01-15 at 7.30.15 AMSome notes on thee specifics of merging vs rebasing with Git.

What is a Merge?
When you merge one branch into another branch the branch being merged into receives a single commit that basically brings it up to the current state of the source branch.

This commit is created automatically by git and essentially represents all of the differences between the branches stuffed into one change. If you were to `git log` in the branch that was merged into, you wouldn’t see any of the commits that had been made in the source branch.

What is a Rebase?
With rebase you basically say “use another branch as new base for my work”.  Behind the scenes what appears to be happening is that git takes the current branch and rewinds any updates you have made on it.  It then moves the starting point to the head of the branch you’re rebasing against.  Finally all of the rewound changes are then applied on TOP of the updated/new starting point.

One thing to keep in mind with rebasing is that it will rewrite commits.  Senko’s blog post explains it pretty poignantly:

In rebase, you change your branch (that’s being rebased) so it looks like it was branched off a new base, not the original one. This involves rewriting the commits, so you’ll end up with different commit IDs.