skills/git-workflows/skills/squash/SKILL.md
Squash commits non-interactively for cleaner history
npx skillsauth add dtsong/my-claude-setup Git SquashInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
--force-with-lease push after squashing already-pushed commits--since <branch>, or --all. Reject zero, negative numbers, non-numeric input, and shell metacharacters.--since): only alphanumeric characters, hyphens, underscores, and forward slashes. Reject spaces, .., or null bytes.Combine multiple commits into fewer, cleaner commits non-interactively.
/git-squash 3 # Squash last 3 commits into 1
/git-squash --since main # Squash all commits since main
/git-squash --all # Squash all commits on branch into 1
/git-squash --preview # Show what would be squashed
# Last N commits
SQUASH_COUNT=3
# Or commits since branching from main
SQUASH_COUNT=$(git rev-list --count main..HEAD)
# Show commits that will be squashed
echo "Commits to squash:"
git log --oneline -n "$SQUASH_COUNT"
# Check for uncommitted changes
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "Commit or stash your changes first."
exit 1
fi
# Ensure we have commits to squash
if [ "$SQUASH_COUNT" -lt 2 ]; then
echo "Need at least 2 commits to squash."
exit 1
fi
# Gather all commit messages
MESSAGES=$(git log --format="%s" -n "$SQUASH_COUNT" | tac)
# Generate combined message
BRANCH=$(git branch --show-current)
echo "Squashed commits from $BRANCH:"
echo ""
echo "$MESSAGES"
# Soft reset to keep changes staged
git reset --soft HEAD~"$SQUASH_COUNT"
# Create new commit with combined message
git commit -m "Combined message here"
Show the squash result and next steps.
Would squash 5 commits:
abc1234 WIP: starting feature
def5678 More work on feature
ghi9012 Fix typo
jkl3456 Actually fix the bug
mno7890 Final touches
Combined changes:
4 files changed, 123 insertions(+), 45 deletions(-)
src/components/Feature.tsx
src/hooks/useFeature.ts
src/styles/feature.css
tests/feature.test.ts
Run without --preview to execute.
Squashed 5 commits into 1:
Before:
abc1234 WIP: starting feature
def5678 More work on feature
ghi9012 Fix typo
jkl3456 Actually fix the bug
mno7890 Final touches
After:
xyz7890 Add feature component with styles and tests
Files in squashed commit:
src/components/Feature.tsx
src/hooks/useFeature.ts
src/styles/feature.css
tests/feature.test.ts
Note: History was rewritten. If already pushed:
git push --force-with-lease
Squashing all commits since main (7 commits)...
Before:
(7 commits with various WIP messages)
After:
feat: Add complete dark mode implementation
- Theme toggle component
- System theme detection
- Persistent preference storage
- Updated color palette
Ready for PR! Run:
/git-push --force-with-lease
/commit-push-pr
feat: Add user authentication
Implements login, logout, and session management.
feat: Add user authentication
- Add login form component
- Implement session management
- Add logout functionality
- Add remember me option
- Add password reset flow
feat: Add user authentication
Squashed commits:
- Add login form component
- Wire up authentication API
- Add session storage
- Fix validation bugs
- Add tests
For more control, use interactive rebase:
# Interactive rebase for last 5 commits
git rebase -i HEAD~5
# In editor, change 'pick' to 'squash' (or 's') for commits to combine
# Then edit the combined commit message
Note: Claude cannot run interactive commands, but can guide you through them.
# Create backup before squashing
git branch backup-before-squash
/git-push to clean up history/commit-push-pr for clean PRs/git-push --force-with-lease after squashing pushed commitsdevelopment
Use when planning implementation steps, deciding commit format, or structuring development approach. Provides brainstorm-plan-implement flow with conventional commits. Triggers on 'how should I approach this', 'commit format'.
development
Security audit checklist for web applications. Use when reviewing, auditing, or hardening a web app's security posture. Covers rate limiting, auth headers, IP blocking, CORS, security middleware, input validation, file upload limits, ORM usage, and password hashing. Triggers on requests like "review security", "harden this app", "security audit", "check for vulnerabilities", or when building/reviewing API endpoints.
development
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
development
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.