git squash commits — combine commits before merging
Quick Answer
# Squash the last 3 commits into one
git rebase -i HEAD~3
# In the editor: change "pick" to "squash" (or "s") for all but the first commit
# Save and close — git opens another editor for the combined commit message
When to use this
You have several "WIP" or "fix typo" commits on your feature branch and want to clean them up before merging.
Other causes & fixes
What the rebase editor looks like
pick abc1234 add login page
squash def5678 fix typo
squash ghi9012 remove console.log
Squash all commits on a feature branch at once
Use the merge-base to find where your branch diverged from main:
git rebase -i $(git merge-base HEAD main)
Push after squashing (force push required)
git push --force-with-lease origin feature-branch
Related