Skip to content
Back to skills

Clean Branches

ASecurity

Clean up unnecessary local branches and prune stale remote-tracking branches

  • 150 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 7, 2026
ai-agentsgobashgit

Security analysis

A100/100

Scanned October 7, 2026

npx -y skills add Goldziher/ai-rulez --skill clean-branches --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clean Branches?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Clean Branches
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/goldziher-clean-branches/badge)](https://www.skillsdirectory.com/skills/goldziher-clean-branches)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.