git squash merge — compress commits

See squash merge compress a branch's messy wip commits into a single clean commit on main. Why it became the default PR merge style.

Scenario

Speed
c1initc2base featurec3wipc4wip fixc5feat donec6Squash merge 'f…HEADmain

Branch state

mainc6◀ HEAD

Current step 9/9

$ git merge --squash feature && git commit

Squash merge compresses all of feature into ONE commit on main. c3–c5 never enter main's history and the feature branch is usually deleted — that's why it's the default for PRs.

$ git log --oneline --all

c6 (HEAD -> main) Squash merge 'feature'

c2 base feature

c1 init

File content (at HEAD) — app.js @ main

1initc1
2basec2
3partAc6
4partBc6
5featCc6
commit abandoned commitHEAD HEAD

Circles are commits; dimmed circles were abandoned by rebase/reset. A prime (c3') means same content, rewritten hash. In sandbox mode, run commands yourself with the buttons.

Squash merge compresses all of a branch's changes into a single commit on your current branch. However many wip, fix, typo commits feature accumulated, main's history gets exactly one 'add feature' commit.

The key difference from a real merge: the squash commit has only ONE parent. There's no history link to the merged branch, so feature's commits become unreachable — which is why the branch is usually deleted alongside.

That's why GitHub offers squash as a default PR merge mode. Review iterations leave messy fixup commits; squashing at merge time turns them into one clean entry. The tradeoff: the detailed per-commit history of the work is gone. Git Branch Simulator

Frequently asked questions

Squash merge vs a normal merge — what's different?
A normal merge creates a two-parent commit linking both histories and preserving every commit. Squash creates a one-parent commit; the source branch's individual commits never enter the history.
What happens to the source branch's commits after squash?
They have no history link to the squash commit, so deleting the branch abandons them — fine, since the content is already merged. Keeping the branch can cause duplicate-merge issues later.
Is this the same as squash in interactive rebase?
No. rebase -i's squash merges commits within one branch (history rewrite). Squash merge is a merge strategy that integrates another branch as a single commit.

Other scenarios

Related tools