How to squash commits during git merge

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Table of contents

Squashing commits during git merge is a powerful technique for maintaining clean, understandable commit history. Let's dive into why and when to use git merge --squash, explore related keywords, and then show how to perform the same action using the Graphite CLI.

git merge --squash branch collects all the changes from a feature branch and stages them on your current branch without creating a merge commit. Then you create a single consolidated commit. This approach avoids creating a cluttered history full of intermediate commits.

FeatureMerge (no squash)Git merge squash
Commit historyPreserves every commitCondenses to one commit
Merge commitYes, maintains branch ancestryNo merge commit
ClarityFull record, often noisyCleaner history
Review easeComplex, multi-step diffSingle diff
  • Git merge squash no commit: Note that --squash prepares the changes but does not create the commit automatically—so you must run git commit yourself.
  1. Update your base and feature branches:

    Terminal
    git checkout feature-branch
    git pull origin main
    git checkout main
    git pull
  2. Squash-merge:

    Terminal
    git merge --squash feature-branch
  3. Inspect:

    Terminal
    git status
    git diff --staged
  4. Commit:

    Terminal
    git commit -m "brief clear feature summary"

    If you want to include all messages, run git commit without -m to open an editor pre-populated with commit summaries.

  5. Push:

    Terminal
    git push origin main
  • Interactive rebase (git rebase -i) lets you squash commits within a branch before merging.
  • Git merge squash squashes at the merge time into another branch.
  • Use rebase squash when you want big control over commit history; use merge squash when you want easy, single-commit trends.

Git squash merge differences: Rebase-derived vs merge-derived squashes; the former preserves branch ancestry with a linear chain, the latter loses that but is simpler.

You cannot squash merge commits (commits with two parents) using interactive rebase. Instead, squash the feature branch then merge --no-ff or use merge squash.

Graphite CLI simplifies layered workflows. It includes a gt squash command to combine a branch's commits into one, with automatic restacking of child branches.

  1. Make sure you're on a stacked feature branch tracked by Graphite.

  2. Run:

    Terminal
    gt squash

    This squashes all commits on the current branch into a single commit, updates branch graph, and restacks downstream branches.

  3. Follow with:

    Terminal
    gt continue

Or use menus in Tower UI: right-click a branch → Squash (same effect).

Graphite integrates with git merge squash with a streamlined workflow: squash branch, then use gt stack submit or gt repo sync to roll your single-commit branch into main elegantly.

  • If you're managing multiple stacked PRs or long-lived branches, Graphite's gt squash is faster and ensures correct restacking.
  • For standalone merges, simple git merge --squash is sufficient.

Graphite's CLI — gt squash — roughly maps to "squash and merge" in one command, plus Graphite's layered branch management.

With Graphite CLI, run gt squash for effortless branch cleanup and continued stack consistency, then merge as usual. By combining core git techniques with Graphite's CLI enhancements, you can maintain efficient, readable, and reliable git history.

Built for the world's fastest engineering teams, now available for everyone