Skip to content

Summary: Worktrees and parallel agents

A worktree is a separate working directory attached to the same git repository: multiple folders sharing one .git/, each with its own branch checked out.

Terminal window
git worktree add <path> <branch> # attach existing branch as new worktree
git worktree add -b <newbranch> <path> <baseref> # create new branch in new worktree
git worktree list # see all attached worktrees
git worktree remove <path> # detach and delete (use --force for unsaved changes)
git worktree prune # clean up records for manually-deleted folders
git worktree lock <path> --reason "..." # prevent accidental pruning
git worktree unlock <path> # release the lock
ToolWhen to use
WorktreeParallel branches on one machine; frequent context-switching; multi-agent workflows; save disk space
CloneTruly independent copies; across machines; want isolation from teammates’ pushes
Checkout-switchingSequential work, done with one branch before starting another, occasional swaps

One branch per worktree: cannot check out the same branch in two worktrees simultaneously. Workaround: different branches or detached HEAD if you need to inspect the same commit.

  1. Review a teammate’s PR without disturbing your current work
  2. Hotfix during a feature: spin up a worktree off main, fix, ship, remove
  3. Side-by-side version comparison: inspect v1.4 and main simultaneously
  4. Multi-agent fleet: one worktree per agent, parallel work, shared history

L14-L16 assume you can spin up multiple parallel working directories cheaply. Worktrees deliver this: one command to create, one to remove, near-zero overhead. Multi-agent AI workflows go from “annoying” with multiple clones to “trivial” with worktrees.

Git stores snapshots. Every other command is just navigating those snapshots.

Worktrees don’t change the snapshots. They just give you more windows looking at the snapshot database simultaneously. Each window shows one branch; together, they show many.

L14 covers the three multi-agent integration patterns built on top of worktrees: shared origin, per-agent fork, shared worktrees. Lead orchestration. Semantic-conflict catching at integration. All assume L13’s worktree foundation.