# Squash Merge

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

**Field:** Software Development  
**Category:** Version Control  
**Also known as:** Squash and Merge, Squash Commits, git merge --squash

## Think of it like

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

## 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

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

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Merge](https://learn.benibix.com/term/development/merge)
- [Pull Request](https://learn.benibix.com/term/development/pull-request)
- [Feature Branch](https://learn.benibix.com/term/development/feature-branch)
- [Rebase](https://learn.benibix.com/term/development/rebase)
- [Fast-Forward Merge](https://learn.benibix.com/term/development/fast-forward-merge)

## Told apart from

- [Squash Merge vs Fast-Forward Merge](https://learn.benibix.com/compare/squash-merge-vs-fast-forward-merge): People think a squash merge and a fast-forward are the same, because both leave main in a straight line. They are not. A fast-forward makes no new commit. Main's label just slides onto the branch's own commits, so every one of them is kept. A squash merge makes one new commit for the whole branch, and the branch's own commits stay off main.

## Taught in

- [Git Merge and Conflicts](https://learn.benibix.com/learn/development-version-control/git-merge-and-conflicts): Git and GitHub, 5/13

![A main branch runs along the top. A feature branch splits off it, gets two commits, and comes back three ways. Fast-forward: main had no new commits, so its label just slides forward to the feature's last commit. Squash merge, lit up: the two feature commits become one new commit on main. Merge commit: a new commit with two parents joins both lines.](https://learn.benibix.com/diagrams/dev3-branch-merges.svg)

---

Source: https://learn.benibix.com/term/development/squash-merge
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
