Git Merge vs Rebase — What's the Difference?

git merge preserves history with a merge commit; git rebase rewrites your branch's commits onto a new base for a linear history. Learn when to use each.

Published September 19, 2026

Merge joins two branches with a merge commit and preserves history exactly as it happened; rebase replays your commits on top of another branch to produce a straight line. Merge is safe for shared branches, rebase gives a cleaner history for your own work.

The concept

git merge creates a commit with two parents. Nothing is rewritten, so the graph shows the true timeline, including the fork.

git rebase takes your commits, rewinds them, moves the branch to the tip of the target and re-applies them as brand-new commits (new hashes). That rewriting is why you must not rebase commits others already pulled.

Same goal, different history

merge: A─B─C─────M (M joins main and feature)
\ /
D─E
rebase: A─B─C─D'─E' (feature replayed on main)

Practical examples

Merge main into your branch

git checkout feature
git merge main

Rebase onto main

git checkout feature
git fetch origin
git rebase origin/main

Resolve a rebase conflict

# fix the files, then
git add .
git rebase --continue
# or bail out
git rebase --abort

Squash messy commits

git rebase -i HEAD~4

Common mistakes

  • Rebasing a branch that teammates have already pulled.
  • Forgetting git push --force-with-lease after a rebase of your own pushed branch.
  • Resolving the same conflict repeatedly instead of rebasing once.

Key takeaways

  • Merge preserves history; rebase rewrites it.
  • Never rebase shared commits.
  • Use rebase locally to tidy, merge to integrate.

FAQ

Which one should my team use?

Many teams rebase feature branches locally and merge (or squash-merge) into main.

Does rebase lose commits?

No, but the commits get new hashes. Old ones remain in reflog.

More Git articles