/olko-git-tools:branch-cleanupfrom olko-git-tools
Prune stale git branches after a merge wave: delete closed/merged remote branches, remove local tracking branches that no longer exist on the remote, and optionally clean up local branches already merged to main. Use after running dependabot-triage, after a sprint wind-down, or when the user says "clean up branches", "prune branches", "delete merged branches", or "tidy up git".
Ships in olko-git-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
🤖 Auto-generated by weekly-pattern-learner · dependabot-triage was added to merge dependency PRs in bulk but leaves stale remote branches behind; no skill follows up to prune them
Remove stale remote and local branches safely after a merge wave. Defaults to dry-run so you see exactly what will be deleted before anything is removed.
origin)main, detect from gh repo view)Always start here. This removes local tracking refs for remote branches that are already gone, without touching anything else:
REMOTE="${Remote:-origin}"
git fetch --prune "$REMOTE"
After pruning, print the count of removed tracking refs:
git branch -vv | grep ': gone]' | wc -l
Find remote branches whose associated PR is merged or closed:
# Get all non-default remote branches
BASE=$(gh repo view --json defaultBranchRef -q '.defaultBranchRef.name' 2>/dev/null || echo "main")
git branch -r --merged "$REMOTE/$BASE" \
| grep -v "HEAD" \
| grep -v "$REMOTE/$BASE" \
| sed "s|$REMOTE/||" \
| sort
Cross-reference with GitHub to confirm each branch's PR state. Only include branches with a confirmed merged or closed PR. An empty result means the branch is not eligible:
STALE_BRANCHES=()
for branch in $(git branch -r --merged "$REMOTE/$BASE" \
| grep -v HEAD | grep -v "$REMOTE/$BASE" | sed "s|$REMOTE/||"); do
PR_DATA=$(gh pr list --head "$branch" --state merged \
--json number,title,mergedAt \
--jq '.[0] | "\(.number) merged \(.mergedAt | .[0:10])"' 2>/dev/null)
if [ -z "$PR_DATA" ]; then
PR_DATA=$(gh pr list --head "$branch" --state closed \
--json number,title,closedAt \
--jq '.[0] | "\(.number) closed \(.closedAt | .[0:10])"' 2>/dev/null)
fi
if [ -n "$PR_DATA" ]; then
echo "$branch ← $PR_DATA"
STALE_BRANCHES+=("$branch")
else
echo "$branch ← no confirmed PR (skipped)"
fi
done
This produces a table like:
dependabot/npm_and_yarn/lodash-4.17.21 ← 42 merged 2026-07-31
dependabot/npm_and_yarn/eslint-8.57.0 ← 43 merged 2026-07-31
feature/login-refresh ← 38 merged 2026-07-28
Never propose deletion of:
| Branch | Reason |
|---|---|
main, master, develop | Protected base branches |
beta, staging, production | Release/deploy targets |
| Any branch with an open PR | May still be in review |
| Any branch not yet merged to base | Would lose commits |
| Branches the user has modified locally in the last 24h | Work-in-progress |
Check for open PRs before including a branch in the deletion list:
OPEN=$(gh pr list --head "$branch" --state open --json number --jq 'length')
[ "$OPEN" -gt 0 ] && echo "SKIP (open PR): $branch"
Print the deletion plan and stop. Never touch the remote without --execute:
Branch cleanup preview, dry-run (pass --execute to apply)
Remote branches to delete (all merged to main):
origin/dependabot/npm_and_yarn/lodash-4.17.21 (PR #42, merged 2026-07-31)
origin/dependabot/npm_and_yarn/eslint-8.57.0 (PR #43, merged 2026-07-31)
origin/feature/login-refresh (PR #38, merged 2026-07-28)
Local tracking refs already pruned: 3 (by git fetch --prune)
Would NOT delete:
origin/beta (protected release branch)
origin/feature/signup (open PR #47)
Run with --execute to apply.
# Delete remote branches
for branch in "${STALE_BRANCHES[@]}"; do
git push "$REMOTE" --delete "$branch" && echo "deleted: $REMOTE/$branch"
done
Only runs when --include-local is explicitly passed.
Find local branches already merged to base and not checked out:
git branch --merged "$BASE" \
| grep -v "^\*" \
| grep -v "$BASE" \
| grep -v "main\|master\|develop\|beta\|staging"
For each candidate, confirm there is no uncommitted work and the tracking ref is gone before deleting:
git branch -vv "$branch" # should show ': gone]' if remote is deleted
git branch -d "$branch" # safe delete: fails if unmerged work exists
Never use -D (force delete): let -d protect you from accidental data loss.
Branch cleanup complete
Remote:
Deleted: 12 branches (10 Dependabot, 2 feature branches, all merged)
Protected: 2 skipped (beta, open PR)
Local tracking refs:
Pruned: 12 stale refs (git fetch --prune)
Local branches (--include-local):
Deleted: 3 branches already merged to main
Kept: 1 branch (has uncommitted work)
Repo now has: N remote branches, M local branches
| Before this skill | After this skill |
|---|---|
olko:dependabot-triage (merged patch PRs) | next olko:morning-routine starts clean |
| Sprint wind-down / milestone close | git fetch confirms clean state |
| Any large batch merge | nothing: maintenance complete |
What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/gh-cliReach for the GitHub CLI (gh) to do something on GitHub from the command line: repositories, issues, pull requests, Actions runs and logs, projects, releases, gists, codespaces, org and extension management. Use when a task needs a gh command and the exact syntax, flag or API path is not obvious, or the user says "use gh", "what is the gh command for", "list my PRs from the CLI", or "query the GitHub API". For driving a PR through review bots and CI use the olko-github-pr skills instead; this one is the command reference.
/git-commitExecute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical groupingOther plugins' skills for the same job
npx claudepluginhub oleg-koval/agent-skills --plugin olko-git-tools