Skip to main content

Git Rebase vs Merge: What Changes, Tested on Git 2.56

Updated 2 min readMarkdown

Git merge joins two histories and adds a merge commit, leaving every existing commit untouched. Git rebase replays your commits on top of another branch, so they get new SHAs and the history becomes a straight line. I ran both on Git 2.56.0 in throwaway repositories, including conflicts, a pushed branch, a squash merge and a revert.

What I saw

  • SHAs: a merge kept my three feature commits as they were and added a merge commit. A rebase gave the same three changes new SHAs (44151c4 became d52c022, and so on) in a straight line.
  • Conflicts: one conflict across two commits was resolved once in a merge and twice in a rebase.
  • Pushing: after a rebase, a plain push was rejected. --force-with-lease refused when a teammate had pushed (stale info), and plain --force removed their commit.
  • Squash: one clean commit, but git branch -d failed with not fully merged.
  • Revert: a merge commit needs git revert -m 1.
git rebase main
git reset --hard ORIG_HEAD   # undid the finished rebase

What I did not test

Interactive rebase, --autosquash, rerere, the pull.rebase config, GitHub's Rebase and merge button, Windows and large histories.

My rule: rebase what only you have, merge what others share. Full post with the pull behavior, --rebase-merges and an FAQ: devtoolhub.com.

No comments yet. Be the first to comment.