Skip to content

Squash

In one line

Squashing combines multiple commits into a single commit, often used before merging to keep history clean.

In simple words

Squashing combines several commits into one. It is commonly used when a feature branch has many small "work in progress" commits that should become a single clean commit when merged into main.

There are two main ways to squash: (1) git rebase -i (interactive rebase) lets you mark commits as "squash" to combine them, and (2) GitHub's "Squash and merge" button on pull requests automatically squashes all PR commits into one.

Squashing keeps the main branch history clean — one commit per feature or PR instead of many small commits. The trade-off is that the granular history of how the feature was developed is lost. Some teams prefer to keep all commits for traceability; others prefer squashed history for readability.

Example

bash
# Interactive rebase to squash
git rebase -i main
# In the editor, change 'pick' to 'squash' for commits to combine:
# pick   abc123 First commit
# squash def456 Second commit
# squash ghi789 Third commit
# Save and edit the combined commit message

Interactive rebase with 'squash' combines commits into one.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary