Skip to content
Skill

Git branch cleanup

Finds merged and stale git branches, then deletes them only after your confirmation

Git branch cleanup is an open-source agent skill for developer tools. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

Scripts
None
Platforms
Claude Code, Codex, Cursor
GitHub stars
12
Last commit
License
MIT
Listing updated

Similar skills

About Git branch cleanup

This skill walks an agent through tidying a git repository's local and remote branches. It first fetches and prunes remote tracking refs, works out the default branch rather than assuming main, and sorts every branch into groups: merged local branches, merged remote branches, orphaned branches whose remote is gone but still hold unmerged work, and active unmerged branches that are left alone.

Before anything is removed, the agent presents a categorized summary and waits for the user to confirm. Deletion uses safe lowercase delete for local branches, so git refuses to remove unmerged work, and bare branch names for remote deletes. Protected names such as the default branch, develop, staging and production are never removed unless the user asks otherwise. A final prune and branch listing confirm the result.

The skill relies on git commands run through the shell, so it needs a git repository with an origin remote and network access to fetch and push deletions.

When your agent uses it

Clean up stale and merged git branches — both local and remote. Prunes tracking refs, identifies merged branches safe to delete, flags orphaned branches whose remote is gone, and presents a clear summary before acting. Use this skill whenever the user mentions cleaning up branches, pruning stale branches, deleting old branches, or tidying their git state. Trigger on: "clean up branches", "delete merged branches", "prune branches", "stale branches", "branch cleanup", "tidy branches", "remove old branches", "git branch cleanup", "branches to delete", "what branches can I delete", or any request about removing branches that have already been merged. Also trigger when the user says things like "I have too many branches", "clean up my git", or "lots of things merged".

From the skill's SKILL.md. Your agent reads this description to decide when to load the skill.

What it can access

From a static check of its 2 files (6 KB) on GitHub on 4 December 2026. Nothing was run. Read the files before you install a skill: it can tell your agent to run anything its tools allow.

Check another skill before you install it.

Install

This skill ships in the skill-madness plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

/plugin marketplace add ivy00johns/Skill-Madness
/plugin install skill-madness@skill-madness

Or copy only this skill to ~/.claude/skills/git-branch-cleanup:

tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/git-branch-cleanup &&
cp -R "$tmp/skills/archive/git-branch-cleanup" ~/.claude/skills/git-branch-cleanup &&
rm -rf "$tmp"

For one project only, put the folder in .claude/skills/git-branch-cleanup inside it instead.

Claude Code docs on skills

Copy the skill folder to ~/.agents/skills/git-branch-cleanup to use it in every repository:

tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/git-branch-cleanup &&
cp -R "$tmp/skills/archive/git-branch-cleanup" ~/.agents/skills/git-branch-cleanup &&
rm -rf "$tmp"

For one repository only, put the folder in .agents/skills/git-branch-cleanup inside it instead.

Codex docs on skills

Copy the skill folder to ~/.cursor/skills/git-branch-cleanup to use it in every project:

tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/git-branch-cleanup &&
cp -R "$tmp/skills/archive/git-branch-cleanup" ~/.cursor/skills/git-branch-cleanup &&
rm -rf "$tmp"

For one project only, put the folder in .cursor/skills/git-branch-cleanup inside it instead.

Cursor docs on skills

Run in a terminal (add --scope workspace to install it for the current workspace only):

gemini skills install https://github.com/ivy00johns/Skill-Madness.git --path skills/archive/git-branch-cleanup

Or copy the folder to ~/.gemini/skills/git-branch-cleanup yourself.

Gemini CLI docs on skills

For GitHub Copilot in VS Code, copy the skill folder to ~/.copilot/skills/git-branch-cleanup:

tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/git-branch-cleanup &&
cp -R "$tmp/skills/archive/git-branch-cleanup" ~/.copilot/skills/git-branch-cleanup &&
rm -rf "$tmp"

For one project only, put the folder in .github/skills/git-branch-cleanup inside it instead.

VS Code docs on skills

Get the folder:

git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git

Then copy Skill-Madness/skills/archive/git-branch-cleanup into your agent's skills folder as git-branch-cleanup. Agents that support SKILL.md read one folder per skill.

The SKILL.md format

What it does

Remote state refresh
Fetches and prunes origin so stale remote tracking refs are removed before analysis.
Default branch detection
Determines the default branch from origin's HEAD, with a fallback to main or master.
Branch categorization
Groups branches into merged, stale remote, orphaned and active unmerged categories.
Confirm before deleting
Presents a summary of every category and waits for approval before any deletion.
Safe deletion rules
Uses non-forced local delete and keeps protected branches such as develop and production.
Final verification
Prunes again and lists remaining branches to report what was removed.

Good for

  • Clean up merged feature branches in my repo
  • Show me which branches I can safely delete
  • Prune stale remote branches that were already merged
  • Tidy my git state after a lot of PRs were merged
  • Find local branches whose remote was deleted but have unmerged work

Git branch cleanup FAQ

Does the skill delete branches without asking?

No. It presents a categorized summary and waits for the user to confirm before deleting anything.

Will Git branch cleanup force-delete unmerged branches?

No. It uses lowercase git branch -d for local branches and only uses forced deletion if the user explicitly asks for it.

Which branches are protected?

The default branch, develop, staging and production (if they exist), and any branch the user asks to keep.

What tools does Git branch cleanup need?

The skill lists Read and Bash as allowed tools and runs git commands, so it needs a git repository with an origin remote.

How do I install Git branch cleanup in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/git-branch-cleanup to use it in all your projects, or to .claude/skills/git-branch-cleanup in one project. Or install the skill-madness plugin, which includes it: /plugin marketplace add ivy00johns/Skill-Madness, then /plugin install skill-madness@skill-madness.

Does Git branch cleanup run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

Which AI agents can use Git branch cleanup?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

What are the best alternatives to Git branch cleanup?

The closest alternatives to Git branch cleanup are Git post merge cleanup, Branch, Git clean worktrees, Check a stale branch is not undoing newer main work and Git merge.

Where this comes from

  • Description: from the skill's own SKILL.md.

More from ivy00johns/Skill-Madness

  1. Finds and removes git worktrees whose changes are already merged into main

    • Open source
    • 12 GitHub stars
    • Developer tools
  2. Bulk-scans a skill ecosystem for consistency, quality gaps and ownership conflicts

    • Open source
    • 12 GitHub stars
    • Developer tools
  3. Runs a single-skill quality review covering structure, triggering and output checks

    • Open source
    • 12 GitHub stars
    • Developer tools
  4. Turns skill review or audit reports into a prioritized list of concrete SKILL.md fixes

    • Open source
    • 12 GitHub stars
    • Developer tools
  5. Applies planned edits to SKILL.md files, validates them, and offers to sync

    • Open source
    • 12 GitHub stars
    • Developer tools
  6. Audits code against integration contracts to find mismatches before runtime tests

    • Open source
    • 12 GitHub stars
    • Developer tools