Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
0xbigboss avatar

Git Worktree Tidy

  • 79 installs
  • 52 repo stars
  • Updated June 24, 2026
  • 0xbigboss/claude-code

git-worktree-tidy is a Claude Code skill that fetches origin, prunes gone branches and orphaned worktrees, and fast-forwards important branches in a bare-repo worktree layout.

About

git-worktree-tidy performs routine hygiene on bare-repo plus worktree layouts: it fetches origin, prunes remote-tracking refs, deletes stale local branches and worktrees, and fast-forwards important branches. A developer runs it to clean up after squash- and rebase-merges. It verifies ship status against the forge's PR merge state because a deleted upstream does not prove the work merged, and it requires confirmation before any destructive action.

  • Fetches origin, prunes gone branches, and removes orphaned worktrees
  • Verifies real ship status against the forge PR merge state, not git ancestry
  • Requires user confirmation before every destructive worktree or branch delete

Git Worktree Tidy by the numbers

  • 79 all-time installs (skills.sh)
  • Ranked #252 of 733 Git & Pull Requests skills by installs in the Skillselion catalog
  • Data as of Jul 30, 2026 (Skillselion catalog sync)
At a glance

git-worktree-tidy capabilities & compatibility

Capabilities
git cleanup · worktree pruning · branch hygiene · ship status verification
Works with
github
Use cases
devops
From the docs

What git-worktree-tidy says it does

Routine hygiene for bare-repo + worktree layouts. Fetches origin, prunes gone branches and orphaned worktrees, and fast-forwards important local branches.
SKILL.md
Never infer "merged/shipped" from `git rev-list origin/main..<branch>` or `git merge-base --is-ancestor` alone.
SKILL.md
npx skills add https://github.com/0xbigboss/claude-code --skill git-worktree-tidy

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs79
repo stars52
Last updatedJune 24, 2026
Repository0xbigboss/claude-code

What it does

Fetch and prune a worktree-based repo, safely delete stale branches and worktrees after verifying PR merge state, and fast-forward important branches.

Who is it for?

Tidying bare-repo plus worktree layouts with many stale branches

Skip if: Deleting branches based on git ancestry alone without forge verification

When should I use this skill?

Asked to 'fetch prune', clean up stale branches/worktrees, or update main/dev to latest

What you get

Stale branches and worktrees are pruned only after PR merge state is verified, and important branches are fast-forwarded to latest.

By the numbers

  • Ten-step workflow from locating the bare root to final status
  • Uses --ff-only when updating branches

Files

SKILL.mdMarkdownGitHub ↗

git-worktree-tidy

Routine hygiene for bare-repo + worktree layouts. Fetches origin, prunes gone branches and orphaned worktrees, and fast-forwards important local branches.

When to use

User asks to "fetch prune", "clean up stale branches/worktrees", or "update main/dev to latest" in a worktree-based repo.

Hard Rules

  • All destructive actions (worktree remove, branch delete) require user

confirmation. Present the full list and wait.

  • Never force-delete a worktree with uncommitted changes without explicit

approval. Flag dirty worktrees separately.

  • Use --ff-only when updating branches. If ff-only fails, stop and ask.
  • Operate from the .bare directory (or repo root) for branch/worktree

management commands.

  • Never infer "merged/shipped" from git rev-list origin/main..<branch> or

git merge-base --is-ancestor alone. Squash- and rebase-merges land the work under a new SHA, so a fully-shipped branch still shows commits "not in main" and a non-ancestor tip. Verify ship status against the forge's PR merge state (step 3a) before classifying a gone branch as unmerged.

Workflow

1) Locate the bare root

Determine the bare repo directory:

  • If cwd contains .bare/, use it
  • Otherwise: git rev-parse --git-common-dir

All branch and worktree management commands run from this directory.

2) Fetch + prune

git fetch --prune origin

Report what was pruned (deleted remote-tracking branches, updated refs).

3) Discover stale branches

git branch -vv | grep ': gone]'

Collect branch names whose upstream is gone.

3a) Verify ship status (gone upstream ≠ merged)

A deleted upstream ("gone") does NOT prove the work shipped, and git ancestry is unreliable here: squash- and rebase-merges land the work under a new SHA, so a fully-shipped branch still shows commits "not in main" and a non-ancestor tip. Verify against the forge before deleting — gone-but-unmerged branches are the only ones that lose real work.

For each gone-upstream branch (GitHub example; substitute your forge CLI):

# Was there a merged PR from this head?
gh pr list --state all --head <branch> \
  --json number,state,mergedAt,mergeCommit \
  --jq '.[] | "#\(.number) \(.state) merged=\(.mergedAt // "no")"'

# If merged, confirm nothing was added to the branch AFTER the merge:
# the local tip should equal the PR head at merge.
gh pr view <pr> --json commits --jq '.commits[-1].oid'   # vs: git rev-parse <branch>

Classify each gone branch:

  • Merged (verified) — a MERGED PR exists AND its head == local tip → shipped,

safe to delete.

  • At risk — no merged PR, or the tip has commits dated after the merge

(git show -s --format=%ci <tip>) → genuine unshipped work. Flag it; do not delete without explicit approval.

If gh/the forge CLI is unavailable, say so and treat unverifiable branches as at risk rather than assuming merged.

4) Discover stale worktrees

git worktree list
git worktree prune --dry-run

Cross-reference worktrees against the gone-branch list. Check each stale worktree for dirty state:

cd <worktree-path> && git status --short

Categorize:

  • Clean + gone: safe to remove
  • Dirty + gone: flag for user review
  • Prunable metadata: orphaned worktree entries (directory already gone)

5) Confirm deletions

Present a summary table:

Stale worktrees to remove:
  <path> (<branch>) [clean]
  <path> (<branch>) [dirty — N uncommitted changes]

Stale branches:
  <branch>  [merged — PR #N, safe to delete]
  <branch>  [AT RISK — no merged PR / commits after merge; review first]

Prunable worktree metadata:
  <entry>

Call out the at risk branches explicitly so the user is deciding with the ship status in front of them. Wait for user confirmation before proceeding.

6) Remove stale worktrees

For each confirmed worktree:

git worktree remove <name>

If removal fails (dirty), report and skip unless user approved force.

7) Delete stale branches

git branch -D <branch1> <branch2> ...

8) Prune worktree metadata

git worktree prune -v

9) Update important branches

Identify which branches have dedicated worktrees for main, dev, or other important branches (user may specify). For each:

cd <worktree-path> && git pull --ff-only origin <branch>

If ff-only fails, report the divergence and ask for guidance.

10) Final status

Show a summary: what was removed, what was updated, any items skipped.

Related skills

FAQ

Does a deleted upstream mean the branch merged?

No; squash- and rebase-merges land work under a new SHA, so the skill verifies against the forge's PR merge state before classifying a gone branch as unmerged.

Does it delete branches automatically?

No; all destructive actions require user confirmation, and dirty worktrees are flagged separately.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.