Repair worktrees after moving the repository

maintenance & cleanup

// what it does

Worktree links are absolute paths by default, so moving the main repository — or moving a worktree with mv instead of git worktree move — breaks them. repair run from the main worktree fixes links to all reachable linked worktrees; run inside a moved linked worktree, or with the new paths as arguments, it reconnects in the other direction.

// shell

$ git worktree repair
$ git worktree repair ../new-location-a ../new-location-b

// gotcha

A linked worktree that suddenly says "fatal: not a git repository" after you renamed or moved the main repo is exactly this failure. If your setup relocates often (external drives, synced folders), set worktree.useRelativePaths=true on recent Git so links survive moves.

// resources