Git worktree is a Git feature that creates additional working copies of a repository in separate directories. Each worktree can be on a different branch, but all share the same commit history and Git objects. This lets you work on multiple branches at the same time without needing to clone the repository multiple times.

How it works

When you create a worktree with the command git worktree add, Git creates a new directory with the files from the chosen branch. That directory is an independent working copy: you can edit, build and test without affecting other worktrees. Under the hood, all worktrees point to the same .git repository, so commits made in one show up in the others.

The advantage is saving space and time. Instead of cloning the entire repository for each branch, you create lightweight worktrees that share objects. When you finish work in a worktree, just remove it with git worktree remove.

Practical example

A developer needs to review a pull request while continuing work on the current feature. Instead of stashing or cloning the repository, they create a worktree for the PR branch. The two tasks stay isolated in different directories, and both can be built and tested at the same time.

In the context of code agents, worktrees are especially useful. Each agent can get its own worktree to work on a task without overwriting the code of the others. This avoids conflicts and allows running multiple agents in parallel on the same project.

What it's for

Git worktree enables real parallelism in development. At bridgecode, each agent in a squad can operate in an isolated worktree, executing and testing changes without stepping on the code of other agents. This makes agent orchestration safer and more traceable.