# Git branch cleanup

> Git branch cleanup is an open-source agent skill for developer tools. Finds merged and stale git branches, then deletes them only after your confirmation. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/ivy00johns/Skill-Madness/tree/main/skills/archive/git-branch-cleanup
- **Repository:** https://github.com/ivy00johns/skill-madness
- **GitHub stars:** 12
- **License:** MIT
- **Skill name:** git-branch-cleanup
- **Collection:** https://github.com/ivy00johns/Skill-Madness
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-03

## About

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".

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/ivy00johns/Skill-Madness/tree/HEAD/skills/archive/git-branch-cleanup)
- [License: MIT](https://github.com/ivy00johns/Skill-Madness/tree/HEAD/skills/archive/git-branch-cleanup)

## Features

- **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

## Install

### Claude Code

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

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

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

```sh
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.

### Codex

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

```sh
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.

### Cursor

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

```sh
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.

### Gemini CLI

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

```sh
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.

### VS Code

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

```sh
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.

### Other agents

Get the folder:

```sh
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.

## 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.

## Alternatives

- [Git post merge cleanup](https://ai-powered.com/skills/git-post-merge-cleanup): Git post merge cleanup is an open-source agent skill for developer tools.
- [Branch](https://ai-powered.com/skills/branch-tjmonsi): Branch is an open-source agent skill for developer tools.
- [Git clean worktrees](https://ai-powered.com/skills/git-clean-worktrees): Git clean worktrees is an open-source agent skill for developer tools.
- [Check a stale branch is not undoing newer main work](https://ai-powered.com/skills/check-a-stale-branch-is-not-undoing-newer-main-work): Check a stale branch is not undoing newer main work is an open-source agent skill for developer tools.
- [Git merge](https://ai-powered.com/skills/git-merge): Git merge is an open-source agent skill for developer tools.
- [Rebase current branch](https://ai-powered.com/skills/rebase-current-branch): Rebase current branch is an open-source agent skill for developer tools.
- [Get git branch](https://ai-powered.com/skills/get-git-branch): Get git branch is an open-source agent skill for developer tools.
- [Fix merge conflicts](https://ai-powered.com/skills/fix-merge-conflicts): Fix merge conflicts is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/git-branch-cleanup
