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 one clean commit, usually with an interactive rebase (git rebase -i) or a squash merge. It tidies noisy history before merging.

How it works

Mark the first commit pick and the rest squash or fixup, then edit the combined message.

Alternatively git merge --squash stages all changes from a branch for a single commit.

Try it

git rebase -i HEAD~3
pick a1b2c3 Add search
squash d4e5f6 fix typo
squash 9f8e7d tweak

Practical examples

Squash the last three

git rebase -i HEAD~3

Squash merge a branch

git switch main
git merge --squash feature
git commit -m "Add search"

Soft reset approach

git reset --soft HEAD~3
git commit -m "Add search"

Update a pushed branch

git push --force-with-lease

Common mistakes

  • Squashing commits others have based work on.
  • Losing useful granular history needlessly.
  • Forgetting force-with-lease after squashing pushed commits.

Key takeaways

  • Squash to tidy history.
  • Interactive rebase or merge --squash.
  • Force push only on your own branch.

FAQ

Squash vs fixup?

fixup discards the commit message; squash lets you combine messages.

GitHub squash and merge?

A button that does a squash merge for you.

More Git articles