How to squash commits in Git
· Category: Git
Short answer
Squashing combines multiple commits into one, making history cleaner and easier to follow.
Steps
- Interactive rebase:
git rebase -i HEAD~4
- Change
picktosquashorsfor commits you want to combine. - Save and edit the commit message.
- Alternatively, squash on merge via GitHub/GitLab.
Tips
- Squash fixup commits and work-in-progress checkpoints.
- Keep logically separate changes unsquashed for better bisecting.
- Always squash before merging feature branches if the team prefers linear history.
Common issues
- Squashing shared commits can cause issues for collaborators.
- Resolving conflicts during interactive rebase requires careful attention.