branch-cleanuplisted
Install: claude install-skill oleg-koval/agent-skills
<!-- Generated by scripts/build-adapters.sh. Do not edit directly. -->
> 🤖 *Auto-generated by **weekly-pattern-learner** · dependabot-triage was added to merge dependency PRs in bulk but leaves stale remote branches behind; no skill follows up to prune them*
# Branch Cleanup
Remove stale remote and local branches safely after a merge wave. Defaults to
dry-run so you see exactly what will be deleted before anything is removed.
## Inputs
- **Remote** (optional, default: `origin`)
- **Base branch** (optional, default: `main`, detect from `gh repo view`)
- **--dry-run** (optional, default: on): preview deletions without executing them
- **--execute**: actually delete branches (requires explicit flag, safety default)
- **--include-local**: also clean up merged local branches (off by default)
## Step 1: Fetch and prune remote tracking references
Always start here. This removes local tracking refs for remote branches that are
already gone, without touching anything else:
```bash
REMOTE="${Remote:-origin}"
git fetch --prune "$REMOTE"
```
After pruning, print the count of removed tracking refs:
```bash
git branch -vv | grep ': gone]' | wc -l
```
## Step 2: Identify stale remote branches
Find remote branches whose associated PR is merged or closed:
```bash
# Get all non-default remote branches
BASE=$(gh repo view --json defaultBranchRef -q '.defaultBranchRef.name' 2>/dev/null || echo "main")
git branch -r --merged "$REMOTE/$BASE" \
| grep -v "HEAD" \
| grep -v "$REMO