Understand where worktree metadata lives

internals & scripting

// what it does

A linked worktree's .git is a file, not a directory — it holds a gitdir: pointer to a private area under the main repository at .git/worktrees/<id>, where that worktree's HEAD, index, and other per-worktree state live. Everything else (objects, refs, config) exists once in the main repository and is shared. git rev-parse --git-dir and --git-common-dir show both halves.

// shell

$ cat ../myapp-hotfix/.git
$ git rev-parse --git-dir --git-common-dir

// gotcha

Copying a worktree directory to a backup or another machine copies only that .git pointer file — the result is broken by design. Archive or clone the main repository instead; worktrees are cheap to recreate.

// resources