Rebase

Rebase is another way to incorporate changes from another branch. But what's the difference from a merge?

The difference lies in the result.

  • A merge keeps the original branch structure. It creates a new merge commit. A loop (or bridge-like) structure is the outcome

  • A rebase moves one branch and connect it to the end of another. This is done by applying the change sets in the side branch onto the target branch. Commits on the side branch will have new HASH values.

The process of taking one commit from another branch and applying it elsehere is called "cherry-picking". A rebase can be considered as chery-picking all commits from the side branch.

Merge vs rebase: rebase will maintain a linear commit history.

But why rebase instead of merge?

There are two main reasons to use rebase over merge:

  • To maintain a linear commit history: some people prefer the history to be clean and tidy. Merge will create the bridge-shape structure in the commit history which can become overwhelming for large projects.

  • To clean up the commit history: there is a variation called interactive rebase which can be used to tidy up previous commits. This is a powerful (and possibly danerous) way to alter the change history.

Last updated