Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.
# Squash last 3 commits interactively
git rebase -i HEAD~3
# In the editor that opens, change 'pick' to 'squash' (or 's'):
# pick abc1234 First commit
# squash def5678 Second commit
# squash ghi9012 Third commit
# Save and close — edit the combined commit message
# Squash all commits on a feature branch into one
git checkout feature/my-feature
git reset --soft main
git commit -m "feat: complete feature implementation"
# Alternative: squash merge (from main)
git checkout main
git merge --squash feature/my-feature
git commit -m "feat: add my feature"
# Fixup (squash without editing message) — keeps first commit message
# In interactive rebase, use 'fixup' or 'f' instead of 'squash'
# pick abc1234 Main commit message
# fixup def5678 WIP
# fixup ghi9012 Fix typoUse Cases
- Cleaning up messy commit history
- Creating a single commit for a pull request
- Combining WIP commits before merging
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Git Interactive Rebase Guide
Interactive rebase to reorder, edit, drop, and squash commits for a clean Git history.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.