What you already know
Retrieval · lessons 03 and 08Two from memory. The first one is why branches alone do not solve this.
How many working trees and indexes does an ordinary git repository have?
Two branches both changed a file, in different places. Does merging them conflict?
One repository, several working trees
Claim + proof · git worktree addThe obvious way to run three agents on one project is three clones. It works, and it costs you three copies of the history, three sets of remotes to keep in sync, and no way to see one agent’s commits from another without pushing.
git worktree is the alternative: additional working trees, each with its own index and its own checked-out branch, all backed by one object database (git-worktree).
$ git worktree add -b agent-retry ../wt-retry $ git worktree add -b agent-parse ../wt-parse $ git worktree list /sandbox/l09/app 4e1d742 [main] /sandbox/l09/wt-parse 4e1d742 [agent-parse] /sandbox/l09/wt-retry 4e1d742 [agent-retry]
Three directories, three branches, one repository. The first line is the original clone; the other two are new directories beside it.
The mechanism is the plainest thing in this course. In a linked worktree, .git is not a directory — it is a file containing one line.
$ cat ../wt-retry/.git
gitdir: /sandbox/l09/app/.git/worktrees/wt-retrySeventy-one bytes. A pointer back to the real repository, which is where every object lives.
Shared: the object database, every branch, every tag, the remotes, the config, and the stash. Not shared: the working tree, the index, and HEAD. So each agent gets its own files and its own staging area, and every commit any of them makes is instantly an object all the others can see.
An agent working in wt-retry makes a commit. From wt-parse, with no fetch, no pull and no push, what does git log --oneline --all show?
$ git log --oneline --all
6301378 Retry five times
4e1d742 Add the appRun from wt-parse, immediately after a commit made in wt-retry.
And git enforces the one rule that makes this safe: a branch can be checked out in at most one worktree. Two agents cannot end up on the same branch by accident.
$ git switch agent-retry fatal: 'agent-retry' is already used by worktree at '/sandbox/l09/wt-retry'
A refusal, naming the directory that holds it. This is the collision that would be worst — two processes rewriting one branch — and it is impossible.
Git shares its own data; it shares nothing else. Each worktree needs its own node_modules, its own build output, and its own .env — because those live in the working tree, and each worktree has a separate one. Untracked files do not travel between them either, which is usually what you want and occasionally a surprise.
git worktree add -b <branch> ../<dir> from any repository. git worktree list shows every one. git worktree remove ../<dir> cleans up, and git worktree prune tidies after a directory you deleted by hand.
Compute the collision
You have read the first 2 steps in full — a claim and the verification that settles it. The rest of this lesson, and the 9 lessons after it, open when subscriptions do. Nothing that is free today will be taken away then.