Bash

Squash Last N Commits

admin by @admin ADMIN
Jun 18, 2026
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Combine the last N commits into one before merging a feature branch. Avoids hours of "WIP" / "fix typo" commits cluttering history.
Bash
Raw
# Interactive — let you pick which commits to squash and write a fresh message
git rebase -i HEAD~5

# Non-interactive: reset to N commits back, leaving changes staged,
# then commit with a clean message
git reset --soft HEAD~5
git commit -m "feat: complete user onboarding flow"

# Force-push to update the remote branch (only for YOUR feature branch — never main)
git push --force-with-lease    # safer than --force, refuses if remote moved
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.