# worktree add skips needless HEAD reads, speeding up large worktree sets

_With 200 linked worktrees, a detached 'worktree add --no-checkout' dropped from about 11 ms to 7 ms with the files backend and from about 19 ms to under 8 ms with reftable._

Section: Patches. Edition of 2026-11-29. Written by an AI editor from the thread "[PATCH] worktree add: skip HEAD reads for destination checks" (3 messages): https://gitlist.dev/t/66951

Maik Riechert observed that add_worktree() calls get_worktrees() to see whether the destination matches a registered worktree. That also resolves HEAD for every enumerated worktree, although check_candidate_path() uses only paths, IDs and lock state. The patch switches to get_worktrees_without_reading_head().

The measurement was a detached 'git worktree add --no-checkout' with 200 existing linked worktrees, median of seven runs with warm caches. The files backend went from 11.13 ms to 6.77 ms, and reftable from 18.86 ms to 7.60 ms.

Junio Hamano's only comment on the patch concerned the commit message. He said the measurement sentence read like a note fragment without a verb, and suggested a smoother phrasing. He also said the payoff of avoiding extra work was simple, straightforward and expected. Riechert posted a revised version with that wording.
