List, repair, and clean up stale Git worktrees

domain: git-scm.com · 7 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. List all working trees with `git worktree list`; the main worktree is listed first, and linked worktrees show their branch, bare/`detached HEAD` status, and any `locked`/`prunable` annotations.
  2. Lock a worktree that must not be pruned/moved/deleted (e.g. on an unmounted portable drive or network share) with `git worktree lock --reason "string" <path>`; unlock later with `git worktree unlock <path>`.
  3. Move a worktree to a new path with `git worktree move <path> <new-path>` (the main worktree and worktrees containing submodules cannot be moved).
  4. After deleting a worktree's directory out-of-band, remove the stale administrative entry with `git worktree prune` (use `-n` for a dry run, or `--expire <time>` to limit pruning).
  5. Repair corrupted/outdated worktree admin files (e.g. after manually relocating the repo) with `git worktree repair <path>...`.
  6. Remove a linked worktree cleanly with `git worktree remove <path>`; use `--force` (twice for locked ones) to remove trees with uncommitted changes.
  7. Official docs: https://git-scm.com/docs/git-worktree

Known gotchas

Related routes

Restore or discard changes to working-tree files with git restore
git-scm.com/git · 6 steps · unrated
Create, list, switch, and delete git branches
git-scm.com/git · 6 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans