Result first: two "agents" edited the same file, app.txt, at the same moment, each in its own folder on its own branch. The main checkout stayed untouched. When I tried to check out the same branch a second time, git refused: fatal: 'agent-a' is already used by worktree.
git worktree add -b agent-a ../wt-a # folder + branch for agent A
git worktree add -b agent-b ../wt-b # folder + branch for agent B
git worktree list # see all of them
git worktree remove ../wt-a # clean up when A's branch is merged
What the docs say: "A git repository can support multiple working trees, allowing you to check out more than one branch at a time." git also has a safeguard: by default it won't create a worktree for a branch that "is already checked out by another worktree" (--force overrides that).
Why this matters for agents:
- Give each agent its own worktree and branch. They never share uncommitted files.
- Review each branch as a normal diff or pull request, one at a time.
- All worktrees share one repository, so commits made in one are visible to the others without pushing. That saves disk space compared with full clones, but it also means a careless
git branch -Din one folder affects every worktree.
Do this now: before your next multi-agent session, create one worktree per agent and point each agent at its own folder.
Sources
- git documentation, git-worktree: https://git-scm.com/docs/git-worktree
From Penloom Studio's free AI lessons: penloomstudio.com
Top comments (0)