prune-branches
Lists merged and stale branches, locally and on origin, and deletes the merged local ones without asking. Use when the branch list has grown or after merging several pull requests.
SKILL.mdskills/repo/prune-branches/SKILL.md
GitHubPrune branches
Remove the branches that are done. Keep everything that still holds work.
When to use
- After merging pull requests.
- The local or remote branch list has become unreadable.
Steps
- Update the view:
git fetch --prune. - List candidates and classify them:
- merged into the default branch:
git branch --merged <default> - gone on the remote:
git branch -vvshowing[origin/... : gone] - stale but unmerged: no commit for several weeks and not merged
- merged into the default branch:
- Never touch the default branch or the branch currently checked out. Switch to the default branch first if a local candidate is checked out elsewhere.
- Drop a candidate that has an open pull request, whichever side it is on.
- For an unmerged, stale candidate, check whether its commits exist anywhere else. If not, report it and leave it alone without asking.
- Delete every merged local branch with
git branch -d, without asking first. - Report the stale and unmerged candidates, local and remote separately, and ask before deleting any of them, and before any remote deletion of any kind.
- Delete a remote branch only after that explicit confirmation, with
git push origin --delete <branch>. - Report what was deleted and what was kept, with the reason for each kept branch.
Guardrails
- Never delete the default branch or the branch currently checked out.
- Never delete a branch that has an open pull request.
- A merged local branch is deleted without asking. Every remote deletion and every stale or unmerged local branch needs an explicit yes first.
- Never force delete (
-D) a branch whose commits exist nowhere else.
Config
pr.base: the branch candidates are measured against. Default: the repository default branch.
References
git-conventionsfor why a branch is deleted once its pull request is merged.