Git in a Minute · intermediate
Git in a Minute: Worktrees
Git worktrees let you check out multiple branches of the same repository into separate directories at once.
Last verified: 2026-09-06
In one sentence
A Git worktree is an additional working directory linked to the same repository, usually checked out on a different branch.
Why it matters
git checkout switches one working tree. That forces serial work. Agents that edit files concurrently will collide unless each agent has its own directory and branch.
How it works
A repository has one main working tree plus zero or more linked worktrees. Each worktree:
- has its own directory on disk;
- checks out one branch (a branch cannot be checked out in two worktrees at once);
- shares the same
.gitobject database.
Create and remove worktrees with git worktree commands. List them when you lose track of agent directories.
Example
git worktree add ../app-feature-a -b feature/a
git worktree add ../app-feature-b -b feature/b
git worktree list
Point each coding agent at its own directory. When finished:
git worktree remove ../app-feature-a
Agentic coding use
Worktrees are the standard pattern for parallel agents: same repo history, separate dirty states, separate branches, merge via pull requests. This is infrastructure for agentic development, not a niche Git trick.
Watch out
Worktrees still share remotes and credentials configuration. Isolation of files is not isolation of secrets or deploy keys. Also clean up stale worktrees or disk and branch clutter will grow quietly.