Brief

Workflow

Git worktrees for parallel AI coding agents: a safe workflow

Use Git worktrees to give parallel AI coding agents separate task workspaces while preserving clear branch ownership, shared-repository limits, integration checks, and safe cleanup.

By the Brief teamFor engineers coordinating concurrent agent changes7 min read
The short answer

Git worktrees let one repository have multiple working trees so different branches can be checked out at the same time. For parallel AI coding agents, give each independent task its own branch and linked worktree, define file and decision ownership, verify each branch in its own workspace, and run integration checks after combining the work. Worktrees separate working files and per-worktree state such as HEAD and the index; they still share the repository and most refs, and they do not isolate ports, databases, credentials, or external services.

Field noteOne repository, separate task workspaces
Each linked worktree has its own working files, HEAD, and index. The worktrees remain attached to one repository and share most refs, so coordination still matters.
On this page 9 sections

Know what a linked worktree separates

A linked worktree creates another checkout attached to the same repository; it is a separate task workspace, not a separate repository or runtime environment.

Git defines one main worktree and zero or more linked worktrees. Each linked worktree has its own checked-out files and private administrative state for items such as HEAD and the index. This is what allows two branches to be checked out at once without repeatedly stashing and switching the main directory.

The repository remains shared. Git documents that refs are generally resolved through the common directory, with limited per-worktree exceptions. Objects, configuration, and repository-level operations can therefore affect more than one workspace. Outside Git, a worktree does not automatically provide separate dependency caches, environment variables, credentials, databases, servers, or ports.

What Git worktrees separate and what they continue to share
BoundaryPer linked worktreeShared or separately managed
Git checkoutWorking files, HEAD, index, and selected per-worktree refsObject database, common configuration, and most refs
Agent taskBranch, diff, task context, and focused validationProduct decisions, repository rules, and integration target
RuntimeOnly what you explicitly configure per workspacePorts, databases, credentials, caches, and external services are not isolated by Git

Parallelize tasks, not dependencies

Use concurrent worktrees when the tasks have distinct outputs and can be reviewed independently; keep dependent or heavily overlapping changes sequential.

Good candidates include a read-only investigation beside an implementation, tests for an already agreed contract, or changes in separate packages with a stable interface between them. Poor candidates include two agents editing the same component, migrations that depend on a still-changing schema decision, or a refactor and feature whose target API has not been settled.

Before creating another workspace, name the reason parallel execution helps. If the workstreams need constant synchronization, the coordination cost is evidence that one bounded sequence may be clearer. Parallel agents should reduce waiting, not create competing versions of the same decision.

  • The tasks can be described without referring to unfinished output from each other.
  • File or symbol ownership is distinct enough to make conflicts exceptional.
  • Each branch has a focused check that can run before integration.
  • One person or primary agent owns shared product and architecture decisions.

Create one named branch and path per task

Start from a known commit, choose an explicit branch name and sibling path, then confirm the resulting worktree list before assigning an agent.

First inspect the main worktree and decide which commit the task should start from. Then create a linked worktree with a new task branch, for example `git worktree add ../brief-auth -b agent/auth-refresh`. Git also supports attaching an existing branch or creating a detached worktree for experiments, but a named task branch is easier to review and retain for normal implementation work.

Run `git worktree list` and enter the new path before starting the agent. Record the absolute workspace path and branch in the task. Git normally prevents the same branch from being checked out in multiple worktrees; do not work around that safety check for routine parallel development.

  1. Inspect the source branch and confirm the intended starting commit.
  2. Choose a short task branch and a specific sibling-directory path.
  3. Create the linked worktree with `git worktree add <path> -b <branch>`.
  4. Run `git worktree list` and confirm the branch-to-path mapping.
  5. Start the agent from that worktree, not from the main checkout.

Give each worktree one bounded mission

Workspace separation helps only when each agent also has a distinct outcome, scope, validation plan, and stop condition.

For every worktree, name the observable result, files or package likely in scope, non-goals, reusable patterns, and the checks expected before handoff. State which shared interfaces are fixed and which decisions belong to the integrator. If an agent discovers that it must edit another workstream's owned surface, it should stop or renegotiate scope rather than quietly crossing over.

Brief can route repository and path-specific evidence inside each workspace. The mission receipt belongs to that branch and task state; it does not prove the other agents saw the same sources. Keep one primary owner responsible for comparing outputs and updating the shared plan when a dependency changes.

Coordinate the state Git does not isolate

Treat servers, ports, databases, caches, generated artifacts, credentials, and external writes as a separate concurrency problem.

Two worktrees can still start the same development server port, run migrations against the same local database, overwrite a shared generated cache, or use credentials with production reach. Give each task an explicit runtime plan: unique ports or databases where needed, safe test accounts, and clear ownership for external mutations.

Repository-level commands also deserve care because the worktrees share common Git data. Coordinate rebases, branch deletion, aggressive cleanup, and hooks. Agents may read shared refs, but only the integrator should rewrite or remove branches that another worktree may still use.

Verify branches separately, then verify the combined change

A passing check in each worktree is necessary evidence, but only integration can expose conflicts between the branches' assumptions.

Before integration, each agent should inspect its branch diff, run the focused checks from that worktree, and hand off changed files, exact results, skips, and remaining risk. The integrator should review each diff against its mission before choosing an order for merge, rebase, or cherry-pick. The right operation depends on the team's Git policy; worktrees do not require one integration strategy.

After combining the branches, rerun checks at the boundary the tasks now share. This may be a package test, a contract suite, a build, or a user flow. A branch can be internally correct and still rely on an interface another branch changed. Do not mark the parent task complete merely because every worker reported completion.

Remove a worktree only after the branch is retained

Confirm the useful changes are committed or otherwise preserved, then use Git's worktree commands to remove the linked workspace and inspect what remains.

Run `git status` inside the linked worktree and confirm the branch or commits are available from the integration path. Use `git worktree remove <path>` for normal cleanup. Git can refuse removal when a worktree contains modifications; treat that refusal as a prompt to inspect the state, not as a reason to force deletion.

If a directory disappeared without a proper removal, `git worktree prune` can clean stale administrative records. Prune is not a substitute for reviewing uncommitted work. Finish by running `git worktree list` so the surviving branch-to-path map is explicit.

Common questions

Questions worth asking next

Are Git worktrees isolated repositories?

No. A linked worktree has separate working files and per-worktree administrative state such as HEAD and the index, but it remains attached to the same repository and shares most refs and Git objects.

Should every parallel AI coding agent get a worktree?

Agents making concurrent edits usually need separate workspaces. Read-only research agents may not. Do not parallelize tasks that depend on unfinished output or require repeated edits to the same files merely because worktrees are available.

Do worktrees isolate development servers and databases?

No. Git worktrees do not create separate ports, processes, databases, credentials, caches, or external services. Configure those boundaries separately before running concurrent agents.