Pruning stale remote branches
Checklist for a repo that's built up years of dead branches. The point is that nothing becomes unrecoverable.
- Check nothing references them. Search
.githubworkflows and branch protection rules for branch names before deleting anything. - Confirm what actually deploys. If Actions only deploys
main, deleting other branches can't break a deploy. - Archive the refs first. Tag them, so a deleted branch can still be recovered by tag. Do this before any deletion, not after.
- Then delete.
- Prune worktrees.
git worktree list, then remove any whose branch is already merged. These accumulate quietly and hold disk.
Steps 1 to 3 are the ones worth not skipping. Deleting is the easy part.