Git squash commits: three small commits become one
By Christophe Paka · Facts checked on 7 November 2026
Your branch is ready for review. Its log reads add feature, fix typo, actually fix. The work is fine, but the story is noise, and a reviewer has to read three commits to see one change.
To git squash commits is to fold several commits into one. You do it with an interactive rebase, before anyone else has the branch. The figure below shows the before and the after.

Use this diagram on your site
Free to share in your blog post, docs, course or slides, as long as the credit link stays. Paste the code below where the figure should go.
How to read this figure
Read the top row. Three commits sit in a row, oldest on the left:
add feature, thenfix typo, thenactually fix. The last two only patch the first. Nobody needs them as separate steps.Follow the arrow down. The arrow is
git rebase -i. An interactive rebase lets you edit the list of commits before Git replays them. You mark the two fix commits as squash.Read the result. One commit is left,
add feature, holding all three changes. Like any rebase, it gets a new ID, so squash only a branch nobody else uses. See why a rebase makes new IDs.
Key takeaways
- Squash noisy commits with
git rebase -ibefore you share a branch, not after. - Mark every line but the first
squash; each one folds into the older commit above it. - Already pushed your own branch? Push the squash with
git push --force-with-lease, never on main.
Try this: squash the last three commits
Use a branch with three commits, add feature, fix typo and a second fix, that nobody else uses.
- Run
git rebase -i HEAD~3.HEAD~3means three commits back from HEAD. Your editor shows three lines, oldest first, each starting withpick. - Change the first word of lines two and three to
squash, so they readsquash 2b259c1 # fix typoandsquash a032d4b # actually fix. Save and close. - Git opens your editor again. Write the final message, then save and close. Git prints
Successfully rebased and updated refs/heads/... - Run
git log --oneline -2to check the branch.
Expected result: One commit where three stood, such as f65c8bf add feature in our run. Your ID differs. If you pushed the branch before, a plain git push is rejected because the host has the old commits; use --force-with-lease.
Questions readers ask
How do I squash my last N commits together?
Run git rebase -i HEAD~N, with your number in place of N. Leave the first line as pick, change the first word of every other line to squash, save, then write one message for the result.
What else can interactive rebase do?
Change the first word of a line: reword changes its message, edit stops so you can amend it, and drop removes the commit and its changes. Moving a line reorders the commits.
What if the rebase stops halfway?
A rebase replays commits one at a time and can stop on a conflict. Fix the file, stage it and run git rebase --continue. Feel lost? git rebase --abort restores the branch as it was before.
Sources: git rebase (official docs); Pro Git: Rebasing.
This figure is from Git Made Crystal Clear, chapter 6.
The chapter builds the idea step by step, with recipes you can follow, a Try it to check yourself, and every source.
Get the book


