cleanup-merged-branches
Originally fromtimschoch/mattpocock-skills
Installation
SKILL.md
Delete remote branches that belong to a merged PR. Destructive, so it runs as a dry-run first and never deletes without explicit confirmation.
Delete rule
A branch is deletable iff all hold — encoded in scripts/plan.sh, the single source of truth:
- it still exists on the remote,
- it has a merged PR,
- it has no open PR,
- it is not protected.
Protected = the default branch + staging. Never delete these, even if a merged PR points at them. A branch with no PR, or only a closed-unmerged PR, is not deletable (it never "belongs to a merged PR"). Extend the protected set in is_protected() inside scripts/plan.sh, nowhere else.
Steps
- Dry-run. Run
bash scripts/plan.sh(pass a remote name as$1if notorigin). It prints deletable branches as<branch> #<pr> <title>, and deletes nothing. Done when you have the list. Empty output → report "nothing to clean up" and stop. - Show + confirm. Show the full list to the user and ask for explicit go. Do not delete on a vague reply — only on a clear yes. This gate is mandatory every run.
- Delete. For each confirmed branch:
git push origin --delete <branch>. Nothing outside the plan's list may be deleted. - Report. List what was deleted; note any push that failed.