Git Squash Cheat Sheet

Squashing Git commits — interactive rebase squash, fixup, autosquash, and best practices for clean commit history before merging.

Last Updated: May 1, 2025

Interactive Rebase Squash

git rebase -i HEAD~4
Interactive rebase last 4 commits
pick → squash
In rebase editor: change 'pick' to 'squash' to meld into previous
pick → fixup
Change 'pick' to 'fixup' — squash AND discard the commit message
pick → reword
Change 'pick' to 'reword' to edit the commit message only
pick → drop
Remove the commit entirely from history
git rebase -i --autosquash HEAD~5
Auto-squash fixup!/squash! commits automatically
git rebase -i --root
Rebase ALL commits from the root (rewrite entire history)
git rebase --continue
Continue after resolving conflicts during rebase

Fixup & Autosquash Workflow

git commit --fixup target-commit
Create a fixup commit targeting a specific commit
git commit --squash target-commit
Create a squash commit with message preservation
git rebase -i --autosquash main
Auto-reorder and squash fixup!/squash! commits
git config --global rebase.autosquash true
Enable autosquash by default
git commit --fixup=amend:/regex/
Fixup the commit whose message matches regex
git rebase -i --autosquash --keep-empty
Autosquash but preserve intentional empty commits

Squash Merge Strategies

ItemDescription
Squash MergeGitHub/GitLab: squash all PR commits into one on merge
Merge CommitKeep all individual commits, add merge commit (full history)
Rebase MergeLinear history, all commits preserved, no merge commit
Semi-Linear MergeRebase then merge commit — linear history with merge marker
Squash + Branch DeleteDefault for most teams: one clean commit per feature
Interactive SquashManually combine related commits, keep logical separations

Best Practices

ItemDescription
Squash WIPsSquash 'WIP', 'fix typo', 'oops' commits before sharing
Keep Logical UnitsOne commit per logical change — don't squash everything
Clean Before ReviewInteractive rebase to polish history before opening PR
Commit Messages MatterA squashed commit needs a high-quality message
Don't Squash Shared HistoryNever rebase/squash commits already pushed to shared branches
Autosquash ConfigSet globally: git config --global rebase.autosquash true
Squash != AmendSquash combines commits; amend replaces the last commit
Co-Author CreditUse Co-authored-by: in squashed merge to credit contributors
Pro Tip: Squash WIP commits before merging, but keep logical steps separate. A PR with one mega-commit is as unhelpful as one with 50 'fix typo' commits.