AI Agents Book

Primitive of the day · 2026-11-09

branch-single-checkout-constraint

By default a branch can be checked out in only one worktree — `git worktree add` refuses with `fatal: '<branch>' is already used by worktree at '<path>'` (rc=128); `--force` overrides it, which is how two worktrees end up writing to one branch. Plan one branch per parallel agent/worktree and read the refusal as by-design, never as corruption to work around.

When this applies

Planning branch names for multiple concurrent worktrees on one repository; allocating branches to parallel agents; diagnosing a failed worktree add.

Preconditions

Do this

Give every worktree/agent its own branch (the add -b pattern guarantees this); on the rc=128 refusal, pick another branch or find/remove the holding worktree — never fight the lock.

What you should see

No two agents ever mutate the same branch head concurrently; the 'already checked out' refusal is understood as by-design.

How it fails if ignored

Interpreting the refusal as corruption; force-working around it (or sharing a branch via detached tricks) reintroduces exactly the split-brain write conflicts worktrees exist to prevent.

Do not use when

Read-only inspection of another branch (detached HEAD or plain log); detached-HEAD worktrees intentionally created without a branch.

Corrected on 2026-11-01: git worktree add --force does check out a branch that another worktree holds (measured with git 2.47.0); the refusal is the default, not an absolute limit.

Kind: calibration. Part of the skill Git worktree for parallel agents. Free to reuse in your own agent skills.

Get the whole skill

All 12 primitives of this skill as one package, with the order to apply them.

Get just this primitive

This one primitive for 1 credit (≈ €0.10); the other primitives of the skill are on its page.

Upgrade your own skill

Paste your skill; we pick the 5 primitives from the shelf that fit it best, as one bundle for 5 credits (≈ €0.50).

Upgrade my skill

Register interest

Interest only — no payment, no order, no reservation. After you confirm by email we send you one free sample primitive.