Table of contents
- What is git merge squash
- Why use squash merge vs merge without squashing
- Step‑by‑step: git merge with squashing
- Interactive rebase vs squash merge differences
- Dealing with merge commits
- Using Graphite CLI to squash commits
- When to use Graphite CLI vs built‑in git commands
- Summary
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.
What is git merge squash
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.
Why use squash merge vs merge without squashing
Feature | Merge (no squash) | Git merge squash |
---|---|---|
Commit history | Preserves every commit | Condenses to one commit |
Merge commit | Yes, maintains branch ancestry | No merge commit |
Clarity | Full record, often noisy | Cleaner history |
Review ease | Complex, multi-step diff | Single diff |
- Git merge squash no commit: Note that
--squash
prepares the changes but does not create the commit automatically—so you must rungit commit
yourself.
Step-by-step: git merge with squashing
Update your base and feature branches:
Terminalgit checkout feature-branchgit pull origin maingit checkout maingit pullSquash-merge:
Terminalgit merge --squash feature-branchInspect:
Terminalgit statusgit diff --stagedCommit:
Terminalgit 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.Push:
Terminalgit push origin main
Interactive rebase vs squash merge differences
- 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.
Dealing with merge commits
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.
Using Graphite CLI to squash commits
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.
Make sure you're on a stacked feature branch tracked by Graphite.
Run:
Terminalgt squashThis squashes all commits on the current branch into a single commit, updates branch graph, and restacks downstream branches.
Follow with:
Terminalgt 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.
When to use Graphite CLI vs built-in git commands
- 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.
Summary
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.