Skip to content
BENIBIX Learn

Squash Merge

Development🔀 Version ControlBranches and History

Also known as Squash and Merge, Squash Commits, git merge --squash

Merging a branch as one commit. Main's history stays short.

Think of it like

Think of it like packing lots of small bags into one big case. Then you carry just one.

Example

Lucy's branch has twelve small commits. She squash-merges it, and main gets one commit: Add a dark mode switch.

Why it matters

Main shows one commit per feature. That is easy to read and easy to undo.

Definition

A squash merge turns all the commits on a branch into one new commit. That one commit lands on the target branch. The small steps, like typo fixes, do not show up in main's history. GitHub offers this as Squash and merge on a pull request. The branch's own commits are not kept on main.

Example code

bash
git switch main
git merge --squash add-dark-mode
git commit -m "Add a dark mode switch"
All the branch's changes become one new commit on main.
Squash merge: two branch commits land on main as one.

Common mistake

Going on with the same branch after a squash merge. Its old commits no longer match main, so conflicts follow.

Key takeaways

  1. 1
    Many become one. All commits are squashed together.
  2. 2
    Clean main. One commit for each feature.
  3. 3
    Start fresh after. Make a new branch for new work.

Compare

Learn it properly