Skip to content
Back to skills

Cleanup Merged Branches

ASecurity

Deletes local and remote git branches that have been merged into main.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
toolsbashgit

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill cleanup-merged-branches --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cleanup Merged Branches?

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

Security grade badge for Cleanup Merged Branches
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-cleanup-merged-branches/badge)](https://www.skillsdirectory.com/skills/david-li0406-cleanup-merged-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-merged-branches
description: "Deletes local and remote git branches that have been merged into main."
---

# Cleanup Merged Branches

This skill safely deletes git branches that have been merged into the main branch.

## Procedure

### 1. Fetch and Prune Remote
```bash
git fetch --prune
```

### 2. List Merged Branches (Preview)
```bash
# Local branches merged into main (excluding main itself)
git branch --merged main | grep -v "main" | grep -v "^\*"

# Remote branches merged into main
git branch -r --merged main | grep -v "main" | grep -v "HEAD"
```

### 3. Delete Local Branches
```bash
git branch --merged main | grep -v "main" | grep -v "^\*" | xargs -r git branch -d
```

### 4. Delete Remote Branches
```bash
# For each remote branch (e.g., origin/feature-branch)
git push origin --delete <branch-name>
```

## Safety Notes

- **Always preview** before deleting (`-d` is safe, `-D` force deletes)
- **Never delete `main`** - the grep filters exclude it
- **Confirm with user** before deleting remote branches (destructive action)
- **Protected branches** - some branches may be protected on GitHub

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…