How to Squash Multiple Commits Into One in Git
Squashing combines several commits into a single one, useful for cleaning up a feature branch's history before merging.
Published September 29, 2026
Squashing combines several commits into a single one, useful for cleaning up a feature branch's history before merging.
Key points
- The most common approach is interactive rebase: git rebase -i HEAD~N, marking all but the first commit as "squash"
- Squashing rewrites commit hashes, so avoid doing it on commits that have already been pushed and shared
- Many Git hosting platforms also offer a "squash and merge" option directly in the pull request UI
Example
git rebase -i HEAD~3