worktree-hygiene

Installation
SKILL.md

Worktree Hygiene

A worktree is shared mutable state. Removal is destructive, a handover is an ownership transfer, and every worktree shares the main repository's .git. Each rule below guards against a destructive failure seen in production.

"An actor" below is anything that writes into a worktree: an agent, a subagent, a human session, a process one of them spawned.

When to Apply

  • Removing a git worktree, or retiring a branch after it landed (its worktree, its local ref, optionally its remote ref)
  • Handing a worktree or branch from one actor to another, or resuming an actor that owns one
  • Several actors (agents, sessions, scripts) share one repository or one worktree
  • Checking out branches or writing git config while other worktrees exist

Removing a Worktree

Verify all three before git worktree remove, freshly, in this order:

  1. Clean, by fresh status codes. Run a fresh git -C <tree> status --porcelain -uall and read the STATUS CODES. Never trust a prior report's dirty count: counts cannot distinguish new files from removal-in-progress deletions, and codes can. -uall overrides a status.showUntrackedFiles=no config that would silently hide untracked files.
Installs
59
Repository
vivswan/skills
GitHub Stars
1
First Seen
Aug 28, 2026