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.
- History: every original commit is kept, plus one merge commit.
- Revert: you must tell git which parent is the mainline, with git revert -m 1 and the merge commit hash. A plain revert fails on a merge commit.
- Good for: teams that want the full story of how a branch was built.
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.
- History: one commit per pull request, easy to read. The branch's own commits are not part of main's history any more.
- Revert: one plain git revert of one commit. This is the easiest case to undo.
- Blame: every line the pull request touched points at the squash commit, not at the small commits you made along the way.
- Good for: teams whose branch commits are noisy (wip, fix typo, fix again).
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.
- If you keep working on the old branch, or build another branch on top of it (a stacked pull request), git sees the old commits as not merged yet. Merging again can replay changes that are already in main and produce conflicts. The usual fix is to rebase the second branch onto main and drop the commits that were already squashed.
- The pull request is the unit of history. If you need to revert half of it, you have to write that by hand, because the halves no longer exist on main.
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.
- History: a straight line with every original commit, rewritten.
- Revert: you revert several commits, newest first, or revert the range. There is no single commit that stands for the pull request.
- Good for: teams that want a linear history and meaningful small commits.
- Watch out: the hashes you saw on the branch are not the hashes on main, so references to them break.
Quick comparison
| Merge commit | Squash | Rebase | |
|---|---|---|---|
| Commits added to main | All of them, plus a merge commit | One | All of them, rewritten |
| Linear history | No | Yes | Yes |
| Revert the whole pull request | git revert -m 1 on the merge commit | git revert on one commit | Revert several commits |
| Original commit hashes kept | Yes | No | No |
| Easiest to read in git log | Medium | Easy | Easy |
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)