Skip to content
Back to skills

Clean Branches

ASecurity

Use when cleaning up local branches, deleting merged branches, pruning stale or gone branches, or tidying `git branch` output. Removes branches whose work has already landed, including squash-merged PRs.

  • 8 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added October 7, 2026
toolsgobashgit

Security analysis

A100/100

Scanned December 5, 2026

npx -y skills add tartinerlabs/skills --skill clean-branches --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clean Branches?

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

Security grade badge for Clean Branches
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tartinerlabs-clean-branches/badge)](https://www.skillsdirectory.com/skills/tartinerlabs-clean-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: clean-branches
description: Use when cleaning up local branches, deleting merged branches, pruning stale or gone branches, or tidying `git branch` output. Removes branches whose work has already landed, including squash-merged PRs.
license: MIT
allowed-tools: Read Bash(git fetch --prune *) Bash(git branch -vv *) Bash(git branch --merged *) Bash(git branch -d *) Bash(git branch --dry-run --delete-merged *) Bash(git branch --delete-merged *) Bash(git --version) Bash(git worktree list *) Bash(git symbolic-ref *) Bash(git rev-parse *) Bash(git remote get-url *) Bash(gh pr list *) Bash(glab mr list *)
model: haiku
effort: low
compatibility: Requires git; `--delete-merged` needs git 2.56+. Squash-merge detection uses a GitHub (gh) or GitLab (glab) remote
metadata:
  short-description: Delete local branches that are already merged.
  title: Clear out old branches
  goal: keep-code-tidy
  audience: developers
---

You delete local branches whose work has already landed, and leave everything else alone.

## Rules Overview

| Rule | Impact | File |
|------|--------|------|
| Merged detection | HIGH | [rules/merged-detection.md](rules/merged-detection.md) |

## Workflow

1. Sync remote state and note the branches that must never be deleted: the current one, and any checked out in a worktree
2. **Native pass**: let git delete the branches it can prove merged into their upstream, previewing first. Skip on git older than the version [rules/merged-detection.md](rules/merged-detection.md) names
3. **Gap pass**: collect the branches the native pass skips (gone or missing upstream), and keep a candidate only when git or the forge confirms it landed. For the forge check, load **only** the matching guide: [references/github.md](references/github.md) for a `github.com` remote (the default), [references/gitlab.md](references/gitlab.md) for GitLab
4. Show the combined list with the evidence per branch (e.g. `#93 merged`, `merged into main`) and confirm before deleting
5. Report what was deleted and what was kept, with the reason for each kept branch — closed-unmerged PR, no PR, upstream ahead, checked out

## Keep, don't guess

A branch with a closed-but-unmerged PR or no PR at all may hold unfinished work. List it as kept and let the user decide; never delete it on age or name alone. Remote branches are out of scope — this skill only touches local refs.

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.

View all in tools →

Comments

Loading comments…

Newsletter

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