Sub topic 2
Choosing Tasks That Can Run Side by Side
Assume you know everyday Git commands, basic shell usage, and how to run a command-line coding agent. Git worktrees help when agents can make mostly independent changes. They do not remove merge conflicts or isolate every kind of machine state.
Choosing Tasks That Can Run Side by Side
Split work by boundaries that minimize shared files and ordering:
- Add authentication, search, and billing as separate features.
- Give each agent a clear output, such as a module, endpoint, or test group.
- Avoid assigning two agents the same configuration, migration, or central routing file.
- Run prerequisite work first when one task needs another task's API or schema.
A good task has a small interface with the other tasks. For example, an agent can build a search service while another adds its user interface, if both agree on the service contract first.
Giving Each Agent Its Own Worktree
A worktree is a working directory connected to one Git repository. Worktrees share Git objects, references, and repository history, but each has separate checked-out files, index, and HEAD. Each agent should use a separate directory and branch.
git worktree add -b agent/auth ../myrepo-auth main
git worktree add -b agent/search ../myrepo-search main
git worktree listThe commands create two branches from main. An agent can edit and commit in its directory without changing the files in the other worktree.
Starting Agents in Parallel
Start each agent from its own directory. A background subshell keeps its directory change local to that process.
for task in auth search billing; do
(
cd "../myrepo-$task"
your-agent-command "Implement the $task task from TASKS.md"
) &
done
waitwait keeps the parent shell running until all agents finish. Capture logs separately when diagnosing failures.
Dependencies, Ports and Untracked Files
Worktrees do not isolate processes, databases, ports, or environment variables. Assign a different port to each development server. Use separate test databases when agents run integration tests. Copy local configuration deliberately rather than assuming untracked files are present.
Exercise
Two agents need to edit the same migration file. Is this a good parallel split?
Show answer
No. Run the migration task first, or redesign the tasks so only one agent owns that file.