Skip to content
Back to skills

Branch Cleanup

ASecurity

Prune merged and stale local and remote branches safely

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 3, 2026
ai-agentsgogit

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add black141312/ada --skill branch-cleanup --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Branch Cleanup?

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

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

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: branch-cleanup
description: Prune merged and stale local and remote branches safely
category: git
---

# Branch Cleanup

Use this to clear out branches that have already merged or gone stale, keeping the branch list readable without deleting unmerged work.

1. Sync references first: `git fetch --prune` to update remotes and drop refs for branches deleted on the remote.
2. List merged branches: `git branch --merged main` shows locals fully merged into main (safe to delete); review the list before acting.
3. Delete merged locals: `git branch -d <name>` (the lowercase `-d` refuses to delete unmerged branches, which is the safety you want).
4. Find stale branches: `git branch -vv` flags ones whose upstream is `[gone]`, and `git for-each-ref --sort=committerdate refs/heads --format='%(committerdate:short) %(refname:short)'` surfaces the oldest.
5. Clean remotes deliberately: `git push origin --delete <name>` for branches you own and confirm are merged; don't delete others' active branches.
6. Re-check `git branch --merged` and `git branch` to confirm only intended branches remain.

## Rules
- Use `git branch -d` (safe) not `-D` (force) unless you've verified the branch is truly disposable — `-D` discards unmerged commits.
- Exclude protected branches (`main`, `develop`, release/*) from any bulk delete; filter them out explicitly.
- `git fetch --prune` only cleans remote-tracking refs, not local branches — do both steps.
- Confirm a remote branch is merged and unowned by an active developer before `--delete`.
- Recover an accidentally-deleted branch via `git reflog` / `git checkout -b <name> <sha>` while the object is still reachable.

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…