clean-branches

Remove merged and stale Git branches with confirmation and optional remote cleanup.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/gupsammy/Claude-setup --skill clean-branches
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clean-branches
Source: https://github.com/gupsammy/Claude-setup/tree/main/skills/clean-branches
Command: npx skills add https://github.com/gupsammy/Claude-setup --skill clean-branches

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers safely remove merged and stale branches from Git repositories, reducing clutter and minimizing the risk of accidental deletions.

Core Features & Use Cases

  • Merged branches cleanup: identifies and lists branches already merged into main (excluding protected ones) so they can be removed with confirmation.
  • Stale branches detection: finds branches without commits for an extended period and flags them for review.
  • Safe deletion workflow: requires explicit confirmation before deleting locally, with optional remote deletions when requested.

Quick Start

Use the clean-branches skill to preview and delete branches as follows.

  1. Update local state: git fetch --all --prune
  2. Identify merged branches (safe to delete): git branch --merged main | grep -v "^*|main|master|develop"
  3. Identify stale branches (no recent commits): git for-each-ref --sort=-committerdate --format='%(refname:short) %(committerdate:relative)' refs/heads/ | while read branch date; do if [[ "$date" == "months" ]] || [[ "$date" == "year" ]]; then echo "$branch ($date)" fi done
  4. Confirm and delete:
  • If you want to delete all merged branches locally: git branch -d <branch-name>
  • If remote cleanup is desired: git push origin --delete <branch-name>

Frequently Asked Questions about clean-branches

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely delete merged Git branches from my local repository?

Safely delete merged Git branches by listing them with git branch --merged main, filtering out protected branches, and executing git branch -d. Explicit confirmation before deletion prevents accidental removal of active development lines.

How do I find and clean up stale Git branches that have no recent commits?

Find stale Git branches by sorting refs with git for-each-ref based on committerdate, filtering those older than months or a year, then deleting them locally with git branch -d to reduce repository clutter and minimize maintenance overhead.

Can I delete remote Git branches while cleaning up local ones?

Yes, you can delete remote Git branches during cleanup by executing git push origin --delete <branch-name>. This optional remote cleanup is supported alongside local deletions but requires explicit confirmation before execution.

How do I protect main or master branches from accidental deletion during cleanup?

Protect main and master branches by applying protected-branch guards that exclude them from deletion lists. When identifying branches for cleanup, filter out main, master, and develop using pattern matching to ensure they remain untouched.

What is the best way to preview Git branches before removing them?

Preview Git branches before removing them by running git fetch --all --prune to update local state, then listing merged and stale branches separately. This safe deletion workflow requires explicit confirmation before executing any deletion commands.

Why should I prune stale and merged Git branches regularly?

Pruning stale and merged Git branches regularly reduces repository clutter and minimizes accidental deletion risks. It maintains a clean local state by removing inactive feature, release, and development branches that are no longer needed.