Skip to content
Back to skills

Cleanup Branches

ASecurity

Git Branch Cleanup

  • 4 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 12, 2026
documentationbashgit

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add MattVOLTA/outworkos_diy --skill cleanup-branches --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cleanup Branches?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cleanup Branches
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattvolta-cleanup-branches/badge)](https://www.skillsdirectory.com/skills/mattvolta-cleanup-branches)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cleanup-branches
description: "Git Branch Cleanup"
argument-hint: "[optional branch pattern]"
disable-model-invocation: true
---

# Git Branch Cleanup

Clean up merged/stale local branches and remove orphaned worktrees.

## Instructions

Perform git branch cleanup for this repository:

### Step 1: Update main and fetch remote state
```bash
git fetch --prune origin
git checkout main
git pull origin main
```

### Step 2: List worktrees and remove stale ones
```bash
git worktree list
```
Remove any worktrees that are no longer needed (branches merged or abandoned).

### Step 3: Identify branches to clean up

**Check for truly merged branches:**
```bash
git branch --merged main
```

**Check for squash-merged branches (compare with GitHub PRs):**
```bash
gh pr list --state merged --limit 50 --json headRefName,number,title
```

Cross-reference local branches against merged PRs. If a local branch has a merged PR, it's safe to delete.

**List local branches with their PR status:**
```bash
for branch in $(git branch --format='%(refname:short)' | grep -v main); do
  pr_state=$(gh pr list --head "$branch" --state all --json state --jq '.[0].state // "NO_PR"')
  echo "$branch: $pr_state"
done
```

### Step 4: Delete merged branches

For each branch that has been merged (either via `--merged` or has a MERGED PR):
```bash
git branch -d <branch-name>    # Safe delete (fails if not merged)
git branch -D <branch-name>    # Force delete (for squash-merged)
```

### Step 5: Clean up remote tracking branches
```bash
git remote prune origin
```

### Step 6: Report summary

Report what was cleaned up:
- Number of branches deleted
- Number of worktrees removed
- Any branches kept and why (no PR, open PR, etc.)

## Safety Rules

1. **Never delete `main`**
2. **Confirm before force-deleting** branches without merged PRs
3. **List before deleting** - always show what will be removed first
4. **Keep branches with OPEN PRs**

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.