Agent skill

Git Branch Cleanup

by gotalab in gotalab/skillport

Analyzes and safely cleans up local Git branches. An agent skill from gotalab/skillport.

MITAuto-check passedDevelopment

Install Git Branch Cleanup

skills CLI
$ npx skills add gotalab/skillport --skill git-branch-cleanup -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install gotalab/skillport git-branch-cleanup --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/gotalab/skillport.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.skills/experimental/git-branch-cleanup .claude/skills/git-branch-cleanup && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
git-branch-cleanup
GitHub stars
414
Token cost
~2k tokens
SKILL.md length
279 words
Files
1
Skills in repo
3
Repo updated
First seen
Licence
MIT

At a glance

Analyzes and safely cleans up local Git branches. An agent skill from gotalab/skillport.

  • Works in 5 steps: Branch Analysis → Categorization → Display Format → …
  • The user wants to clean up branches
  • SKILL.md covers Contents, Quick Start, Workflow and Commands Reference, plus 2 more sections
  • Calls git

What it does

Git Branch Cleanup is an agent skill from gotalab/skillport. Analyzes and safely cleans up local Git branches. Categorizes branches by merge status, staleness, and remote tracking. Provides interactive selection with safety guards. Use when the user wants to clean up branches, delete old branches, organize Git branches, or asks about which branches can be safely deleted.

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts. Compatibility notes: Requires git 2.17+ (for worktree support). Git 2.22+ recommended for git branch --show-current.

It sits in Development, covering Git workflow. It works with Model Context Protocol. The repository describes itself as: Bring Agent Skills to Any AI Agent and Coding Agent — via CLI or MCP. Manage once, serve anywhere. The licence is MIT.

When your agent uses it

  • The user wants to clean up branches
  • Delete old branches
  • Organize Git branches
  • Asks about which branches can be safely deleted

Example prompts

  • “Use the git-branch-cleanup skill to analyz and safely cleans up local Git branches. An agent skill from gotalab/skillport”
  • “/git-branch-cleanup”

Requirements

  • Compatibility (from SKILL.md): Requires git 2.17+ (for worktree support). Git 2.22+ recommended for `git branch --show-current`.

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Branch Analysis
  2. Categorization
  3. Display Format
  4. Safety Guards
  5. Execute Deletion

What it can do on your machine

Read from SKILL.md and the folder at commit 51334ae. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • git

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Requires git 2.17+ (for worktree support). Git 2.22+ recommended for `git branch --show-current`.

    From compatibility in the SKILL.md frontmatter.

Context cost

Git Branch Cleanup loads about 2k tokens when it runs. Until then it costs about 83 tokens; SKILL.md has 279 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~83
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from gotalab/skillport at commit 51334ae, republished under its MIT licence (© gotalab). 279 words, ~1,980 tokens.

Download SKILL.mdSave it as .claude/skills/git-branch-cleanup/SKILL.md (or your agent's skills folder).
name
git-branch-cleanup
description
Analyzes and safely cleans up local Git branches. Categorizes branches by merge status, staleness, and remote tracking. Provides interactive selection with safety guards. Use when the user wants to clean up branches, delete old branches, organize Git branches, or asks about which branches can be safely deleted.
compatibility
Requires git 2.17+ (for worktree support). Git 2.22+ recommended for `git branch --show-current`.

Git Branch Cleanup

Safely organize and clean up local Git branches. Categorizes branches by merge status, staleness, and remote tracking, then guides users through safe deletion.

Contents

  • Quick Start
  • Workflow (Steps 1-5)
  • Commands Reference
  • Dry Run Mode
  • Safety Checklist

Quick Start

  1. Analyze branches (Step 1)
  2. Categorize by safety level (Step 2)
  3. Display results and ask user which to delete (Step 3)
  4. Verify against safety guards (Step 4)
  5. Execute deletion after confirmation (Step 5)

Workflow

Step 1: Branch Analysis

Collect information with these commands:

bash
# Decide base branch (prefer auto-detect; fallback to main)
BASE_BRANCH="$(
  git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's@^origin/@@'
)"
[ -n "$BASE_BRANCH" ] || BASE_BRANCH=main

# List all branches with last commit date
git for-each-ref --sort=-committerdate refs/heads/ \
  --format='%(refname:short)|%(committerdate:relative)|%(upstream:trackshort)|%(contents:subject)'

# Merged branches (against base)
git branch --merged "$BASE_BRANCH"

# Unmerged branches
git branch --no-merged "$BASE_BRANCH"

# Branches whose upstream is gone (remote deleted)
git branch -vv | grep -F ': gone]' || true

# List worktrees (branches with '+' prefix in git branch -v have worktrees)
git worktree list

# Branches with worktrees ('+' prefix indicates worktree association)
git branch -v | grep '^+' || true

# Branches ahead of upstream (have unpushed commits)
git for-each-ref refs/heads \
  --format='%(refname:short) %(upstream:trackshort)' \
  | grep '>' || true
Step 2: Categorization

Categorize branches by safety level:

CategoryDescriptionSafety
Merged (Safe)Already merged to base branchSafe to delete
Gone RemoteRemote branch deletedReview recommended
StaleNo commits for 30+ daysNeeds review
Has WorktreeBranch checked out in a worktree (+ prefix in git branch -v)Remove worktree first
Ahead of UpstreamHas unpushed commits⚠️ Do not delete
UnmergedActive work in progressUse caution

Note: 30 days is a reasonable default for stale detection. Adjust based on team's sprint cycle if needed (e.g., 14 days for 2-week sprints).

Step 3: Display Format
## Branch Analysis Results

### Safe to Delete (Merged)
  - feature/login (3 weeks ago) - Add login feature
  - fix/typo (2 months ago) - Fix typo in readme

### Remote Deleted
  - feature/old-api (1 month ago) - Remote branch no longer exists

### ⚠️ Ahead of Upstream (DO NOT DELETE)
  - feature/wip (1 day ago) - Has 3 unpushed commits

### Stale Branches (30+ days)
  - experiment/cache (2 months ago) - Unmerged

### Active (Unmerged)
  - feature/new-dashboard (2 days ago) - Work in progress

---
Which categories would you like to delete?
1. Merged only (safest)
2. Merged + remote deleted
3. Select individually
Step 4: Safety Guards

Never delete these branches:

  • main
  • master
  • trunk
  • develop
  • development
  • Currently checked out branch

Always confirm before deletion:

The following branches will be deleted:
  - feature/login
  - fix/typo

Continue? (y/N)
Step 5: Execute Deletion
bash
# After confirmation
git branch -d <branch-name>  # For merged branches
git branch -D <branch-name>  # Force delete (unmerged)

For branches with worktrees, remove the worktree first:

bash
# Check if branch has a worktree
git worktree list | grep "\\[$branch\\]"

# Remove worktree before deleting branch
git worktree remove --force /path/to/worktree
git branch -D <branch-name>

Bulk delete [gone] branches with worktree handling:

bash
# Process all [gone] branches, handling worktrees automatically
git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}' | while read branch; do
  echo "Processing branch: $branch"
  # Find and remove worktree if it exists
  worktree=$(git worktree list | grep "\\[$branch\\]" | awk '{print $1}')
  if [ ! -z "$worktree" ] && [ "$worktree" != "$(git rev-parse --show-toplevel)" ]; then
    echo "  Removing worktree: $worktree"
    git worktree remove --force "$worktree"
  fi
  # Delete the branch
  echo "  Deleting branch: $branch"
  git branch -D "$branch"
done

Commands Reference

bash
# Bulk delete merged branches (excluding protected branches and current branch)
# Notes:
# - Uses for loop + case for bash/zsh compatibility (avoids `while IFS= read` issues in zsh).
# - Uses case statement for exact-name matching (avoids grep regex edge cases).
# - Always exclude the current branch to prevent accidental self-deletion.
BASE_BRANCH="$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's@^origin/@@')"
[ -n "$BASE_BRANCH" ] || BASE_BRANCH=main
CURRENT_BRANCH="$(git branch --show-current)"
for branch in $(git branch --merged "$BASE_BRANCH" | sed 's/^[* ]*//'); do
  case "$branch" in
    main|master|trunk|develop|development|"$CURRENT_BRANCH"|"") continue ;;
    *) git branch -d "$branch" ;;
  esac
done

# Prune remote-tracking references (requires network access)
# Note: This may fail if offline or remote is unreachable.
# If it fails, skip this step - branch analysis still works with cached remote data.
git fetch --prune || echo "Warning: Could not reach remote. Using cached data."

# List oldest branches (30+ days)
git for-each-ref --sort=committerdate refs/heads/ \
  --format='%(committerdate:short) %(refname:short)' | head -20

# Worktree commands
git worktree list                              # List all worktrees
git worktree remove /path/to/worktree          # Remove a worktree
git worktree remove --force /path/to/worktree  # Force remove (even if dirty)
git worktree prune                             # Clean up stale worktree refs

Dry Run Mode

Preview deletions without executing:

bash
# Preview only
BASE_BRANCH="$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's@^origin/@@')"
[ -n "$BASE_BRANCH" ] || BASE_BRANCH=main
CURRENT_BRANCH="$(git branch --show-current)"
for branch in $(git branch --merged "$BASE_BRANCH" | sed 's/^[* ]*//'); do
  case "$branch" in
    main|master|trunk|develop|development|"$CURRENT_BRANCH"|"") ;;
    *) echo "$branch" ;;
  esac
done

Trigger dry-run mode if user says "--dry-run", "preview", or "just show me".

Safety Checklist

Before deletion, verify:

  • Not the current branch
  • Not a protected branch (base/main/master/trunk/develop)
  • No unpushed commits (ahead of upstream)
  • Worktree removed first (if branch has associated worktree)
  • User confirmation obtained
Quick safety commands
bash
# Show "ahead/behind" vs upstream for each local branch
git for-each-ref refs/heads \
  --format='%(refname:short)|%(upstream:short)|%(upstream:trackshort)|%(committerdate:relative)|%(contents:subject)' \
  --sort=-committerdate

# For a specific branch, confirm it's not ahead of upstream (if upstream exists)
# (Empty output => nothing unpushed)
git log --oneline @{u}..HEAD 2>/dev/null || echo "No upstream configured for this branch"

# Check if a branch has an associated worktree
# ('+' prefix in git branch -v output indicates worktree)
git branch -v | grep "^+" | awk '{print $2}'

# Find worktree path for a specific branch
git worktree list | grep "\\[branch-name\\]"

© gotalab, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .skills/experimental/git-branch-cleanup of gotalab/skillport.

Open the folder on GitHubat commit 51334ae

Compare with similar skills

Git Branch Cleanup next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Git Branch Cleanup compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Git Branch Cleanup this skillgotalab/skillport414—~2kAutomated safety check: PassMIT
Git Workflow And Versioningshashankswe2020-ux/whoop-mcp1653 repos~2.6kAutomated safety check: NotesMIT
Cut Releasespiculedata/saiku1.3k—~502Automated safety check: PassApache-2.0
Release NotesGlitterKill/sdl-mcp491—~925Automated safety check: PassCustom licence
E2b Sandboxagent-sandbox/agent-sandbox218—~2.6kAutomated safety check: PassApache-2.0
GitHubswarmclawai/swarmclaw688—~820Automated safety check: PassMIT

Similar skills

  • Git Workflow And Versioning

    shashankswe2020-ux/whoop-mcp

    Structures git workflow practices. An agent skill from shashankswe2020-ux/whoop-mcp.

    165 GitHub starsUsed in 3 repos~2.6k tokens
    DevelopmentAuto-check: notes
  • Cut Release

    spiculedata/saiku

    Cut a Saiku release via Gitflow — version bump, release branch, PR to main, tag, back-merge, and post-release chores.

    1.3k GitHub stars~502 tokensUpdated today
    DevelopmentAuto-check passed
  • Release Notes

    GlitterKill/sdl-mcp

    Generate a CHANGELOG.md entry from git history since the last tag, categorized by type (features, fixes, security, breaking changes).

    491 GitHub stars~925 tokensUpdated 17 days ago
    DevelopmentAuto-check passed
  • E2b Sandbox

    agent-sandbox/agent-sandbox

    Create, manage, and use E2B sandboxes — run commands, manage files, use git, persist state, and configure networking.

    218 GitHub stars~2.6k tokensUpdated 19 days ago
    DevelopmentAuto-check passed
  • GitHub

    swarmclawai/swarmclaw

    GitHub operations via gh CLI: issues, PRs, CI runs, code review, API queries.

    688 GitHub stars~820 tokensUpdated 3 mo ago
    DevelopmentAuto-check passed
  • Drives the basemind code-intelligence tool from the command line for symbol search, callers, git history and blame, document search and web crawling, sharing its cache with the MCP server.

    108 GitHub stars~2k tokensUpdated today
    DevelopmentAuto-check passed

More from gotalab/skillport

  • Opus 4 5 Migration

    gotalab/skillport

    Migrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5.

    414 GitHub starsUsed in 4 repos~1.2k tokens
    Auto-check passed
  • Skill Evaluator

    gotalab/skillport

    Evaluates agent skills against Anthropic's best practices. An agent skill from gotalab/skillport.

    414 GitHub stars~1.6k tokensUpdated 3 mo ago
    Auto-check passed

Categories

Questions about Git Branch Cleanup

What does Git Branch Cleanup do?

Analyzes and safely cleans up local Git branches. An agent skill from gotalab/skillport. Git Branch Cleanup is an agent skill from gotalab/skillport. Analyzes and safely cleans up local Git branches.

When should I use Git Branch Cleanup?

Git Branch Cleanup fits situations like: the user wants to clean up branches; delete old branches; organize Git branches; asks about which branches can be safely deleted.

How do I install Git Branch Cleanup in Claude Code?

Run `npx skills add gotalab/skillport --skill git-branch-cleanup -a claude-code`. Or copy the skill folder (.skills/experimental/git-branch-cleanup in gotalab/skillport) into .claude/skills/git-branch-cleanup in your project. Claude Code loads it when a task matches its description.

How do I install Git Branch Cleanup in Codex?

Run `npx skills add gotalab/skillport --skill git-branch-cleanup -a codex`. Or copy the skill folder (.skills/experimental/git-branch-cleanup in gotalab/skillport) into .agents/skills/git-branch-cleanup in your project. Codex loads it when a task matches its description.

Can I use Git Branch Cleanup in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add gotalab/skillport --skill git-branch-cleanup -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/git-branch-cleanup, .gemini/skills/git-branch-cleanup, .github/skills/git-branch-cleanup and .opencode/skills/git-branch-cleanup in your project.

What does Git Branch Cleanup need to run?

Going by SKILL.md and its folder, Git Branch Cleanup needs the command-line tools its instructions call (git). Compatibility (from SKILL.md): Requires git 2.17+ (for worktree support). Git 2.22+ recommended for `git branch --show-current`..

Does Git Branch Cleanup access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Git Branch Cleanup safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Git Branch Cleanup use?

Git Branch Cleanup is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Git Branch Cleanup use?

About 2k tokens (SKILL.md is roughly 7.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Git Branch Cleanup?

Skills that share tags, products or a category with Git Branch Cleanup: Git Workflow And Versioning (shashankswe2020-ux/whoop-mcp, 165 stars), Cut Release (spiculedata/saiku, 1.3k stars), Release Notes (GlitterKill/sdl-mcp, 491 stars) and E2b Sandbox (agent-sandbox/agent-sandbox, 218 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Git Branch Cleanup?

gotalab (a GitHub user) maintains it in gotalab/skillport, which has 414 GitHub stars. The repository holds 3 skills in this directory. The repository was last updated on June 24, 2026.

Source: gotalab/skillport on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.