Video in progress

Middle 🌿 Git

On GitHub there are three ways to merge a PR: merge commit, squash and merge, and rebase and merge. How do they differ in the history?

A merge commit keeps all the commits from the branch and the merge commit that joins them. Squash turns the whole PR into a single commit on main. Rebase and merge puts each commit on top of main separately, but without a merge commit.

📖 Answer

Say the PR has 5 commits.

  • Merge commit: 5 commits + 1 merge commit on main. The full history is kept and the PR boundary is clear. But small commits like "fix typo" end up on main too.
  • Squash and merge: one commit on main, with a message usually taken from the PR title. main is clean: one commit = one feature = one PR. Reverting is easy too. The downside: the internal steps are lost, and the local branch looks "not merged".
  • Rebase and merge: the 5 commits are rewritten and added to main one after another. The history is linear, but every commit must be good quality, otherwise wip commits show up on main.

Many teams make squash the default, because people's commit discipline varies. If the team deliberately splits commits into logical pieces (with interactive rebase), rebase and merge is better, since git bisect works more precisely.

What matters is to pick one rule per repository and turn off the others in the GitHub settings. A mixed history is hard to read.