clean-branches — Claude Code skill: tidy up your git branches
A skill that walks your local git branches, finds merged and orphaned ones, and deletes them one at a time with a closing report.
npx skills add dyoshikawa/rulesync --skill clean-branches -a claude-codeWhat clean-branches does
The skill runs in five steps. It starts by reading the current state: git branch --show-current, the branch list, git remote show origin and git branch -vv. From that it picks out the current branch, the default branch and any branch whose upstream is gone. Merged branches come from git branch --merged <default-branch>.
Next it refreshes remote refs with git fetch --prune, and git remote prune origin when needed. Deletion is limited to branches that are clearly done: merged into the default branch, or left without an upstream. The current and default branches are off limits, and unmerged ones only go after you approve force deletion with git branch -D. Anything ambiguous gets shown to you first.
Branches are removed one by one, never through a broad wildcard. The wrap-up lists what was deleted, what was skipped and why, and whether stale remote-tracking branches were pruned. Worth installing if merges have left you with a pile of branches and no appetite to sort them by hand.
What it helps with
- drop local branches already merged into main
- clear out branches whose upstream was deleted
- refresh remote refs and prune vanished branches
- get a report of what was deleted and what was skipped
- delete branches one at a time instead of one wide command
Example prompts for the agent
- clean up the local branches in this repo
- remove merged branches and prune the remote ones
- list the branches you'd delete and ask me first
How to install clean-branches
1Skills CLI (Vercel)
npx skills add dyoshikawa/rulesync --skill clean-branches -a claude-code2Manually: put the files in place
~/.claude/skills/clean-branches/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/clean-branches/
1Skills CLI (Vercel)
npx skills add dyoshikawa/rulesync --skill clean-branches -a codex2Manually: put the files in place
.agents/skills/clean-branches/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add dyoshikawa/rulesync --skill clean-branches -a cursor2Manually: put the files in place
.cursor/skills/clean-branches/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install dyoshikawa/rulesync clean-branches2Manually: put the files in place
.github/skills/clean-branches/SKILL.md1Skills CLI (Vercel)
npx skills add dyoshikawa/rulesync --skill clean-branches -a gemini-cli2Platform CLI
gemini skills install https://github.com/dyoshikawa/rulesync --path .rulesync/skills/clean-branchesManually: put the files in place
.devin/skills/clean-branches/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add dyoshikawa/rulesync --skill clean-branches -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about clean-branches
How do I install clean-branches in Claude?
Run npx skills add dyoshikawa/rulesync --skill clean-branches -a claude-code. The skill lands in ~/.claude/skills/clean-branches/SKILL.md.
What does clean-branches do?
It finds local branches merged into the default branch plus branches with a deleted upstream, then deletes them one by one. It also runs git fetch --prune and reports back.
Will it delete a branch with unmerged work?
Unmerged branches are only touched after you explicitly approve force deletion, and then via git branch -D. The current and default branches are never deleted.
Source text
SKILL.md · MIT
--- name: clean-branches description: Clean up unnecessary local branches and prune stale remote-tracking branches targets: - "*" --- # Clean Branches Clean up unnecessary local branches and prune stale remote-tracking branches. ## Step 1: Inspect Current State Run the following: - `git branch --show-current` - `git branch --format='%(refname:short)'` - `git remote show origin` - `git branch -vv` Identify: - The current branch - The default branch (for example `main` or `master`) - Branches whose upstream has been deleted After identifying the default branch, list branches already merged into it: - `git branch --merged <default-branch>` If you want to use the remote-tracking branch as the source of truth, use: - `git branch --merged origin/<default-branch>` ## Step 2: Refresh Remote State Update remote refs and prune deleted remote branches: ```bash git fetch --prune ``` If needed, also run: ```bash git remote prune origin ``` ## Step 3: Select Branches to Delete Delete only branches that are clearly unnecessary. Safe candidates include: - Local branches already merged into the default branch you identified above - Local branches whose upstream branch is gone and are no longer needed Never delete: - The current branch - The default branch - Branches that are not fully merged unless the user explicitly asks for force deletion If there is any ambiguity, show the candidate branches to the user and ask for confirmation. ## Step 4: Delete Branches For merged branches, delete them safely: ```bash git branch -d <branch-name> ``` Only if the user explicitly approves force deletion for unmerged branches, use: ```bash git branch -D <branch-name> ``` Delete branches one by one, not with a broad wildcard command. ## Step 5: Report Result Summarize: - Which branches were deleted - Which branches were skipped and why - Whether stale remote-tracking branches were pruned
© dyoshikawa · MIT · dyoshikawa/rulesync