Merge commit vs squash vs rebase: what each GitHub merge actually does

GitHub gives you three ways to merge a pull request. They end with the same code on your main branch, but the history they leave behind is different, and that difference shows up later when you revert, bisect or look at who changed a line.

Create a merge commit

Git adds one new commit with two parents: the tip of your main branch and the tip of the pull request branch. Every commit from the branch stays in the history, with its own hash, and the merge commit marks the point where they joined.

Squash and merge

All the commits in the pull request are combined into one new commit on the main branch. The commit has one parent, your main branch, and one message. By default GitHub builds the message from the pull request title and number, and lists the individual commit messages in the body.

What happens when you squash

Squashing creates a brand new commit. Git does not remember that this commit stands for the branch's commits. That has two consequences worth knowing.

Rebase and merge

Each commit in the pull request is replayed on top of the main branch, one at a time. No merge commit is created. The commits keep their messages but get new hashes, because their parent changed.

Quick comparison

Merge commitSquashRebase
Commits added to mainAll of them, plus a merge commitOneAll of them, rewritten
Linear historyNoYesYes
Revert the whole pull requestgit revert -m 1 on the merge commitgit revert on one commitRevert several commits
Original commit hashes keptYesNoNo
Easiest to read in git logMediumEasyEasy

Which should you pick?

Pick one per repository and stay with it. Squash is a good default for teams that open small pull requests and want each one to be one reversible unit. Merge commits suit teams that care about the branch's history. Rebase suits teams that already keep clean, small commits.

Why it matters for scheduled merges and reverts

Merge Scheduler uses the method you set for each repository, and if a deploy fails it opens a revert pull request for you. Squash makes that revert one commit. A merge commit is reverted with the right mainline parent. A rebase merge needs several commits reverted. If your team reverts often, that is a good reason to prefer squash.

Do this in Merge Scheduler: Connect GitHub and add your first repository

Related: How to revert a merge in git (git revert -m 1) and why re-merging does nothing · GitHub auto-merge, merge queue and scheduled merge: what each is for · How to automatically revert a failed deploy (and when not to)