bashintermediate
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.
bashPress ⌘/Ctrl + Shift + C to copy
# 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.
bashintermediate
Interactive Rebase — Squash and Reorder
Use git rebase -i to squash, edit, reorder, or drop commits before pushing to clean up history.
Best for: Cleaning commit history before merging a PR
#git#rebase
bashadvanced
Git Interactive Rebase Guide
Interactive rebase to reorder, edit, drop, and squash commits for a clean Git history.
Best for: Crafting a clean commit history before merge
#git#rebase
bashadvanced
Git Rebase Strategies Guide
Advanced rebase strategies for cleaning history including onto, autosquash, and conflict resolution.
Best for: Cleaning commit history before merging
#git#rebase
bashintermediate
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Best for: Keeping feature branches linear with main
#git#rebase