skills/workflow-repository/managing-git-worktrees/SKILL.md
Create, inspect, attach, repair, remove, or prune local Git worktrees while preserving branches, detached commits, and tracked, untracked, ignored, and submodule data. Use for the full worktree lifecycle or optional branch cleanup.
npx skillsauth add narumiruna/agent-skills managing-git-worktreesInstall 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.
Inspect before mutation. Keep worktree operations separate from commits, pushes, rebases, and unrelated branch changes. Treat dynamic refs and paths as untrusted: validate them, pass them as argv when possible, and quote shell values.
git worktree list --porcelain -z; the first record identifies the main worktree. If it is bare or stale, request a storage root or repair it before deriving paths.For a new path, default the storage root to $HOME/.worktrees; if $HOME is unset or unusable, request an explicit root. Create the root if absent, then use <root>/<main-name>-<branch-with-slashes-replaced-by-hyphens>. Stop on an existing path or normalization collision rather than inventing a suffix.
git check-ref-format --branch "$branch" and resolve the start point to one commit with git rev-parse --verify --end-of-options "${start_point}^{commit}".git show-ref --verify and occupancy from porcelain records; do not substring-match.git worktree add -b "$branch" "$worktree_path" "$start_oid" # new branch
git worktree add "$worktree_path" "$branch" # existing free branch
Stop if the branch is checked out elsewhere; do not bypass occupancy with --force. Verify the exact record and git -C "$worktree_path" status --short --branch.
git -C "$worktree_path" status --porcelain=v1 --untracked-files=all --ignored=matching --ignore-submodules=none
Expand directory entries when needed and inspect initialized submodules recursively. Every tracked, ??, and !! entry can be lost.
3. For detached targets, record HEAD and check reachability:
git for-each-ref --format='%(refname)' --contains="$head_oid" refs/heads refs/tags refs/remotes
Preserve an otherwise unreachable commit with a user-named branch or tag before removal.
4. Stop on a lock. Unlock only after explicit confirmation that the lock is no longer needed.
5. If loss inventory is empty and reachability is safe, run git worktree remove "$worktree_path" and verify its record disappeared.
6. If local-only data exists, display the complete loss and require approval that names it. Use --force only when Git requires it and that exact loss was approved; ignored data may disappear even without --force.
7. Preserve the branch by default. Never delete the directory directly as a substitute for git worktree remove.
Delete only when separately requested. Resolve the branch and user-chosen comparison ref to commits and prove ancestry with git merge-base --is-ancestor. Reverify the branch still points to the inspected object, then try git branch -d.
If the branch is unmerged or -d checks a different upstream/current-HEAD relationship than the chosen comparison, explain the mismatch. Use git branch -D only after separate approval to discard or bypass that exact condition and after rechecking object identity and ancestry.
Use git worktree repair for moved worktrees and verify every repaired record. A missing path is not proof that its data should be abandoned.
Prune only when the directory is genuinely gone and recovery is not wanted. Protect detached commits as above, preview with git worktree prune --dry-run --verbose, show the exact preview, then run the matching prune only after approval. Pruning metadata is not directory or branch deletion.
development
Score or compare one or more agent skills across trigger clarity, workflow actionability, safety boundaries, verification rigor, incremental knowledge value, and leanness. Use only when the user explicitly asks for ratings, numerical quality scores, rubric-based scorecards, or scored comparisons; use creating-agent-skills for unscored reviews or revisions.
development
Assess or improve an existing codebase's architecture when the user asks about module boundaries, coupling, scattered ownership, testability, change locality, deep modules, seams, or behavior-preserving structural refactoring. Use for cross-module design rather than ordinary diff review or a confirmed edge-case bug fix.
development
Perform read-only security audits, vulnerability assessments, or threat-focused reviews of diffs, pull requests, code paths, or explicitly scoped repositories when security is the primary objective or acceptance criterion. Use reviewing-code for ordinary review with baseline security coverage and hardening-code-paths for fixing confirmed findings.
development
Run iterative multi-reviewer panels over a code diff, verify their findings, apply explicitly authorized fixes, and re-review the updated change until it passes or reaches a stopping condition. Use when the user asks for a panel loop, multi-model code-review consensus, or a review-fix-re-review cycle.