Skip to content

Merge vs. Rebase

Question

Difference between merge and rebase.

Short interview answer

Merge combines histories and normally creates a merge commit when the histories have diverged. Rebase replays a branch’s commits onto another base, creating new commits and therefore rewriting that branch’s history.

Detailed answer

Suppose main receives commit M while a feature branch has commits F1 and F2. A merge can connect both lines of history with a merge commit. A rebase can replay the feature changes on top of M, producing new commits equivalent in content to F1 and F2 but with new identities. Rebasing can make a local, unshared feature history linear; merging preserves the existing topology. Do not casually rebase commits that other people are already basing work on, because their history no longer shares the same commit identities.

Sources