worktree-branch-rationalization
Installation
SKILL.md
worktree-branch-rationalization — collapse the sprawl, lose nothing worth keeping
Harvest first. Delete last. The canonical line plus a few protected branches is the destination.
⚠️ Critical Constraints
- Harvest before you prune — always. Capture the best content onto a staging branch and commit it before removing any worktree or deleting any branch. Deletion is the last phase, never an early shortcut.
- Why: a deleted branch's unmerged commits are only recoverable from reflog for a limited window; an orphaned-worktree branch may have the only copy of real work. Pruning first turns recoverable into lost.
- WRONG:
git worktree prune && git branch -D feature-x(delete, then hope it merged). - CORRECT: confirm
feature-xis contained in staging (git branch --merged staging), thengit branch -d feature-x(lowercase-drefuses to drop unmerged work).
- Never remove a worktree with a dirty or locked working tree. Run
git -C <worktree> status --porcelainfirst; uncommitted changes there are not in any branch.- Why:
git worktree remove --forceon a dirty tree silently discards uncommitted edits — the exact agent-swarm output you are trying to save.
- Why:
- Never touch the protected set. The default branch, release/maintenance branches, and any branch with an open PR are off-limits to deletion regardless of merge state.
- Why: "merged into staging" is not the same as "safe to delete from origin"; protected branches may carry history other people depend on.
- Use
-dnot-Das the default. Reserve-D(force) for branches you have individually confirmed are fully harvested.- Why:
-Dskips the "is this merged?" safety check; defaulting to it defeats the whole skill.
- Why: