# clean-branches

clean-branches — a command that systematically removes merged and inactive branches from Git. Keeps your repository clean by deleting obsolete branches and syncing local state with the remote.

- command · `type=command` · Claude Code, Codex, GitHub Copilot, Gemini CLI · ★ 1357 repo stars
- Author: qdhenry
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/qdhenry/Claude-Command-Suite/tree/HEAD/.claude/commands/dev/clean-branches.md
- Updated: 2026-03-01
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/commands/clean-branches

## What it does

clean-branches runs a complete branch audit: checks repository state, identifies the default branch, finds branches merged into main, and locates stale branches with no recent activity. It works step by step, analyzing first and asking for confirmation before deletion, making it safe to remove both local and remote-tracking branches.

The command uses standard Git tools: `git branch --merged` to find merged branches, `git for-each-ref` to analyze by commit date, and `git remote prune` to sync remote-tracking references. A built-in script protects critical branches—main, master, develop, staging, production—so they stay untouched.

It supports interactive mode with confirmation before each deletion, shows unmerged changes on a branch before removing it, and logs which branches were cleaned. If uncommitted changes exist, the command stashes them first.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/commands/clean-branches.md` — Call it with /clean-branches. For all projects use ~/.claude/commands/

### Codex

**Manually: put the files in place**
- File: `~/.codex/prompts/clean-branches.md` — Call it with /prompts:clean-branches. Codex marks this format deprecated in favour of skills

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/prompts/clean-branches.prompt.md`

### Gemini CLI

**Manually: put the files in place**
- File: `.gemini/commands/clean-branches.toml` — Gemini stores commands as TOML: the prompt text goes into the prompt field

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/qdhenry/Claude-Command-Suite/tree/HEAD/.claude/commands/dev/clean-branches.md

## When to use it
- Delete branches that have been merged into main
- Remove stale branches inactive for more than thirty days
- Sync local remote-tracking branches with the remote server
- Prevent accidental deletion of critical branches
- Generate a report of deleted branches

## Example prompts
- Clean up merged branches and synchronize the local repository state
- Find and remove branches with no updates in the last month
- Delete the `feature/old-feature` branch and sync with origin

## Similar
- [clean_gone](https://affpapa.org/en/nevibecode/commands/clean-gone.md) — command · ★ 47914 repo stars
- [github-workflow](https://affpapa.org/en/nevibecode/skills/transilienceai-github-workflow.md) — skill · 195 installs
- [worktree](https://affpapa.org/en/nevibecode/commands/worktree.md) — command · ★ 6529 repo stars
- [update-branch-name](https://affpapa.org/en/nevibecode/plugins/update-branch-name.md) — plugin · ★ 1013 repo stars
- [speckit-git-feature](https://affpapa.org/en/nevibecode/skills/speckit-git-feature.md) — skill · ★ 110 repo stars
- [new-branch-and-pr](https://affpapa.org/en/nevibecode/skills/new-branch-and-pr.md) — skill · 2300 installs

From the same set: [qdhenry/claude-command-suite](https://affpapa.org/en/nevibecode/by/qdhenry/claude-command-suite.md) — 112 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
