GitHub offers three ways to merge a pull request: create a merge commit, squash and merge, and rebase and merge. A merge commit keeps every commit and adds one commit that joins the branches. Squash and merge combines all commits of the pull request into one new commit. Rebase and merge replays each commit on top of the target branch without a merge commit. The choice decides how readable your history is, so it is worth understanding before you click the button.
If you are comparing github squash and merge vs rebase, the short answer is that squash gives one commit per pull request and rebase keeps every commit but rewrites it. The details below show the history each option produces.
Assume main has commits A and B, and a feature branch was created from B with two commits C and D. Meanwhile someone added commit E to main:
Each option below shows what main looks like after the pull request is merged.
This is the classic option. GitHub runs a merge that joins the two lines of history:
M is a new merge commit with two parents. C and D stay exactly as you wrote them, with the same hashes. Nothing is rewritten, and the history records that a branch existed and when it was joined.
Use it when you want a complete, honest record, or when several people committed to the same branch and their individual commits must stay intact. The cost is a busier history with many merge commits, which makes git log --oneline harder to scan.
GitHub takes all changes of the pull request, creates one new commit on the target branch, and discards the individual commits from the branch's history:
S contains the combined changes of C and D. The default message is built from the pull request title and the list of commit messages, and you can edit it before confirming. The original commits still exist in the pull request page, but they are not part of main.
Squash is a good default for teams that work with many small, messy commits such as "fix typo" or "wip". Every pull request becomes one clean commit that is easy to read, revert (git revert <hash> undoes the whole feature) and bisect. The trade-off is that you lose the detailed steps, and a long pull request that mixes several ideas becomes one large commit. Keep pull requests small and focused when you squash.
GitHub replays the commits of the branch on top of the current tip of main, one after another, and moves main forward without a merge commit:
C' and D' have the same changes as C and D, but they are new commits with new hashes, because their parent changed. The history is perfectly linear and keeps each commit separate.
This option works well when the branch has a few carefully written commits that each make sense alone. Two points matter in practice. First, the hashes change, so anyone who based work on the old branch commits must update their copy. Second, commits made through the web interface this way are not signed by your key, so repositories that require signed commits may not allow it.
| Aspect | Merge commit | Squash and merge | Rebase and merge |
|---|---|---|---|
Commits added to main | Original commits plus a merge commit | One new commit | Original changes as new commits |
| History shape | Branches visible | Linear | Linear |
| Original hashes kept | Yes | No | No |
| Easy to revert a whole pull request | One revert of the merge commit with -m 1 | One simple revert | Needs one revert per commit |
| Best for | Full record, long-lived branches | Many small or messy commits | A few clean, meaningful commits |
The repository owner decides which methods appear on the merge button. In the repository settings, under General and Pull Requests, you can enable or disable each of the three options. Many teams keep only one, so that every pull request lands the same way and the history stays consistent.
A reasonable rule of thumb:
You can also set the default option, which controls what the button shows first. The setting is only a convenience; whoever merges can still switch among the allowed methods.
The squashed commits do not appear on the target branch, but they remain visible in the pull request and in the source branch until it is deleted. The final state of the code is identical to the other options.
Yes. Because the whole pull request is one commit, git revert <hash> removes it in one step. GitHub also shows a Revert button on merged pull requests that creates a new pull request for you.
A commit's hash depends on its parent. After the replay the parent is different, so each commit gets a new hash even though the change is the same.
Maintainers often prefer squash and merge, because contributor branches can be untidy and the result is one commit per accepted contribution. The right choice is whatever the project documents, so check the contributing guide.
Merge commits preserve everything and show branches, squash gives one clean commit per pull request, and rebase keeps separate commits in a straight line while changing their hashes. Pick one method per repository, enforce it in the settings, and keep pull requests small so the history stays useful.