| name | fold |
| description | Use when the user asks to clean up, squash, reorganize, or rewrite commit history on the current branch before a PR. Groups messy commits into logical, reviewable units while preserving meaningful history. |
/fold — Commit Cleanup
You are PolyForge's commit organizer. Turn a messy branch into clean, logical commits.
Usage
/fold Clean up current branch against main/master
/fold origin/develop Clean up against a specific base branch
Process
Step 1: Analyze
git merge-base HEAD origin/main || git merge-base HEAD origin/master
git log --oneline --reverse origin/main..HEAD
git diff origin/main..HEAD --stat
Under 3 commits → "Only {N} commits — nothing to clean up." Stop.
Over 2000 lines diff: Spawn [model: sonnet] subagent for per-file categorization → returns JSON: [{ "file": "", "category": "" }]
Step 2: Categorize
Group: Schema/Infrastructure | Core Implementation | API/Interface | Tests | Documentation | Cleanup
Cleanup commits always absorbed into parent — never standalone.
Step 3: Propose
Current: 18 commits → Proposed: 4 commits
1. feat(db): add user preferences migration + model
← squashes: "add migration", "add model", "fix lint"
2. feat(api): add preferences endpoints + service
← squashes: "add service", "add controller", "fix type error"
Call AskUserQuestion — "How should I proceed?" with options: "Apply" / "Show diffs per group" / "Adjust grouping" / "Cancel" / "Other". See @skills/shared/common-patterns.md § "User Questions — AskUserQuestion ONLY".
Step 4: Execute
git reset --soft $(git merge-base HEAD origin/main)
git add <schema files> && git commit -m "feat(db): ..."
git add <core files> && git commit -m "feat(api): ..."
Step 5: Verify
git diff origin/main..HEAD --stat
{test command}
Show: before/after commit count, diff identical confirmation, test status.
Call AskUserQuestion — "Push with --force-with-lease?" with options: "Push now" / "Skip push" / "Other" (only if remote branch exists).
Step 6: Update PR
If PR exists: preserve template structure, update only summary/changes.
Rules
- Target: 3-7 commits — never squash everything into 1
- Never lose code — verify diff stat before and after
- Commit format:
type(scope): short description + key details
- Use
--force-with-lease not --force