devlk
c/learning u/devlk Team

Merge, squash or rebase: which should I use for pull requests?

Team FAQ: this question comes up often, so we've answered it below. Add your own experience, or a different view, in the comments.

GitHub offers "Create a merge commit", "Squash and merge" and "Rebase and merge". What's the difference, and which one should a team use?

1
1 comment
No account needed: you'll get a random guest name, kept on this device. Or sign up to choose yours.
Sort by: Best Top New Old
devlk Team·

All three get your changes into main. They differ in what the history looks like afterwards.

Option What happens Good for
Merge commit Keeps every commit from the branch, plus a merge commit joining the two Seeing exactly how work happened; long-lived branches
Squash and merge Combines the whole pull request into one commit on main Clean, readable history; branches with messy "wip" commits
Rebase and merge Replays each commit on top of main, no merge commit Linear history while keeping individual, well-written commits

A sensible default for most teams: squash and merge. One pull request becomes one commit, which makes git log, git revert and git bisect easy. Use the PR title as the commit subject.

On your own branch, git rebase main (or git pull --rebase) keeps your branch up to date without extra merge commits.

The one rule that matters: never rebase or force-push a branch that other people are working on. Rebasing rewrites commits, and their copies will no longer match. If you must update your own PR branch after rebasing, use git push --force-with-lease, which refuses to overwrite commits you haven't seen.

Whatever you choose, pick one as a team and set it in the repo settings (Settings > General > Pull Requests) so everyone does the same thing.

What does your team use, and has it caused any problems?

1