skills/git-cleanup/SKILL.md
--- name: git-cleanup description: Prune local git branches that are already on main, detecting classic merges, squash-merges via merged PRs, and content-in-main via diff. Confirms with the user before deleting. Use when the user wants to clean up, prune, or delete merged branches, or asks which branches are safe to delete. category: development argument-hint: [--base main] [--dry-run] [--include-archive] [--yes] allowed-tools: Bash(git *) Bash(gh *) --- # Git Cleanup List every local branch,
npx skillsauth add RonanCodes/ronan-skills skills/git-cleanupInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
List every local branch, classify it against main, and delete the ones the user confirms. Works with squash-merge workflows where git branch --merged is blind.
git branch --merged main only detects merge-commits and fast-forwards. Under a squash-only workflow (see /ro:new-tanstack-app step 13a and connections-helper/docs/adr/0002-github-branch-protection-squash-only-merges.md), branches get merged by replaying their diff into a new single commit on main. The original commit SHAs are never in main's history, so --merged marks them as unmerged even though their content is fully landed.
This skill combines three detection strategies so the result is correct regardless of merge strategy.
/ro:git-cleanup # interactive, asks before deleting
/ro:git-cleanup --dry-run # show the report, touch nothing
/ro:git-cleanup --base master # if the repo uses master instead of main
/ro:git-cleanup --include-archive # include branches named backup/*, archive/*, heads/*
/ro:git-cleanup --yes # skip confirmation, delete every confirmed-merged branch
For each local branch (excluding current + base):
git branch --merged <base>. Deletable with -d.gh pr list --head <branch> --state merged --json number returns at least one merged PR. The original commits are not in main but the PR was merged. Deletable with -D (force).git diff <base>..<branch> is empty. The branch's tree is identical to main. Deletable with -D. (Rare but possible: branch was rebased to match main without a PR, or the same changes were committed independently on both.)Branch names matching backup/*, archive/*, heads/* are treated as archive-intentional and skipped by default. Include with --include-archive.
# Ensure we're in a git repo
git rev-parse --git-dir >/dev/null 2>&1 || { echo "not a git repo"; exit 1; }
# Working tree cleanliness is NOT required (we're only touching refs, not files)
# Base branch exists
BASE=${BASE:-main}
git rev-parse --verify "$BASE" >/dev/null 2>&1 || { echo "base branch $BASE not found"; exit 1; }
# Stash current state? No: we don't modify the tree. But if current branch is
# about to be deleted (shouldn't happen, we skip current), bail.
CURRENT=$(git rev-parse --abbrev-ref HEAD)
git fetch --prune origin
This also removes stale origin/* remote-tracking branches whose remote was auto-deleted by delete_branch_on_merge: true.
Build a table. One row per local branch (excluding $CURRENT and $BASE):
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads/ | grep -vE "^($CURRENT|$BASE)$"); do
# Skip archive-ish names unless --include-archive
if [[ "$branch" =~ ^(backup|archive|heads)/ ]] && [ -z "$INCLUDE_ARCHIVE" ]; then
status="archive-skip"
# Strategy 1: classic merge
elif git branch --merged "$BASE" | grep -qE "^ $branch$"; then
status="classic-merged"
# Strategy 2: merged PR on GitHub
elif command -v gh >/dev/null && gh pr list --head "$branch" --state merged --json number --jq '.[0].number' 2>/dev/null | grep -q .; then
pr=$(gh pr list --head "$branch" --state merged --json number --jq '.[0].number')
status="squash-merged-pr#$pr"
# Strategy 3: content in main
elif [ -z "$(git diff "$BASE..$branch")" ]; then
status="content-in-main"
else
# Check unpushed / ahead state
ahead=$(git rev-list --count "$BASE..$branch")
status="unmerged-ahead-$ahead"
fi
echo "$status | $branch"
done
Print a grouped summary. Example:
Classic-merged (safe, -d deletion):
- chore/pnpm-pin
- fix/og-external-fonts
Squash-merged via PR (use -D, PR confirms intent):
- chore/github-hygiene-and-commitlint (PR #19 merged)
- test/visual-home-baselines (PR #18 merged)
Content matches main (use -D):
- feat/rebased-onto-main
Archive-style (kept by convention, use --include-archive to delete):
- backup/feat-prism-mock-server-pre-split
- heads/pre-tanstack-migration
Unmerged (NOT proposed for deletion):
- feat/wip-xyz (3 commits ahead of main)
Stashes on this repo (informational only, not touched):
- stash@{0}: user-wip-prism-mock (73 minutes ago)
- stash@{1}: pre-migration-working-state (6 days ago)
Use AskUserQuestion with 3 options:
Skip the question if --yes was passed.
# classic-merged: -d (asserts git thinks it's merged)
git branch -d "$branch"
# squash-merged-pr / content-in-main: -D (force, because git doesn't know)
git branch -D "$branch"
Record each deletion and its prior SHA in the final summary, so the user can recover with git branch <name> <sha> if a delete was wrong.
Print:
unmerged-ahead-N (future /ro:git-cleanup runs will keep skipping them).gh installed: skip strategy 2. Classic-merged + content-in-main still work, so the skill is still useful, just misses squash-merged-PR cases where the branch had no patch-equivalent landing.gh: strategy 2 fails silently (its query errors, we treat as "no merged PR"). Report at the end: "gh auth missing, squash-merge detection was skipped, here are the branches that could have been squash-merged that we couldn't verify."origin: fetch step no-ops. All detection still works against the local $BASE.$CURRENT). Print a note suggesting git checkout $BASE then re-run.main has moved since last fetch: fetch step at the start prevents stale classification.git branch --merged <base> uses local <base>, not origin/<base>. Without the fetch, a branch merged to origin but not pulled locally would be misclassified as unmerged. The fetch step prevents this.gh pr list --head <branch> matches the branch name, not the SHA. If the branch was renamed after the PR merged, detection misses it. Unusual edge case.git branch <name> <sha> can recover./ro:stacked-prs: the rebase flow this skill's output enables (once the parent is cleanly merged-and-pruned)./ro:gh-ship: opens the PR in the first place. Most branches this skill deletes were opened by gh-ship.connections-helper/docs/adr/0002-github-branch-protection-squash-only-merges.md.github-branch-protection-and-squash-merges in llm-wiki-research.development
--- name: worktree description: Coordinate multiple agents on one repo via a worktree-lock pool, so two agents never clobber each other's working tree. Acquire the first free slot (main, then beta/gamma… worktrees, created on demand), work there on your own branch, release when you've pushed. Use before modifying any repo that might be in use by another agent (factory, dataforce, etc.), or whenever you're told a repo is being worked on. Backed by `ro worktree`. category: development argument-hin
testing
--- name: ship description: Ship a feature branch the local-CI-first way — run the full local gate, push, open a PR, squash-merge, then deploy, without waiting on GitHub Actions. Use when a branch is ready for main and you want it merged and deployed now. Reads CI policy from `ro ci` (default skips remote CI because GitHub Actions billing keeps hitting limits). Sibling to /ro:gh-ship (waits on GitHub checks) and /ro:cf-ship (the deploy half). Triggers on "ship it", "ship this", "merge and deploy
testing
--- name: setup-logging description: Set up (or audit) the observability stack in a TanStack Start + Cloudflare Workers app so it is "diagnosable by default" — structured logging (logtape) with a request context carrying trace_id + userId + tenant/orgId, a trace_id propagated FE→BE→logs→Sentry→PostHog, Cloudflare Workers observability enabled, and Sentry + PostHog wired. Two modes: `setup` (wire it into an app) and `audit` (check an existing app + report gaps). Use when scaffolding a new app, wh
development
Manage credentials INSIDE the active ~/.claude/.env file — read which token/account to use for a given app (Simplicity vs Dataforce vs Ronan-personal), add or update a secret WITHOUT it passing through the chat (an interactive Terminal window prompts for it), and track secrets that were exposed in a transcript so they get rotated. Sibling to /ro:context (which switches WHICH env file is active). Use when the user wants to add an API key/token/secret, asks "which credential do I use for X", needs the env organized/labelled, or a secret was pasted into the chat and should be rotated.