How to use git worktrees with AI coding agents
A git worktree is a second working folder for the same repository, checked out on its own branch. Give each coding agent its own worktree and the agents edit in parallel without overwriting each other or your checkout, and every branch ends as its own pull request.
Why agents need their own folder
Two agents in one checkout write to the same files. You cannot tell whose change is whose, and a test run by one agent reads files the other is still editing.
Your own work has the same problem. Uncommitted changes in your checkout mix with whatever an agent edits there, so you cannot review the agent alone.
A worktree fixes this without a second clone. It has its own files, its own branch and its own changes, and it shares the repository history with the main checkout.
Set one up by hand
These are the git commands behind the idea, with a repository called payments-api.
- Create a worktree on a new branch, next to your checkout.
git worktree add -b fix/webhook-retry ../payments-api-retry origin/main - Prepare it like a fresh clone. Git-ignored files such as .env.local and installed dependencies are not in a fresh worktree, so copy what the agent needs and run your install.
- Start the agent inside that folder.
cd ../payments-api-retry - List your worktrees whenever you lose track.
git worktree list - After the branch is merged, go back to your checkout, then remove the folder and the branch.
cd ../payments-api git worktree remove ../payments-api-retry git branch -d fix/webhook-retry
How Goodboy does it
Goodboy runs those steps for you, one worktree for each branch an agent works on.
One worktree for each branch
Each branch gets its own worktree, a separate folder with its own changes and its own pull request, so agents edit in parallel without touching your checkout. The folder is named gb- and six characters, such as gb-7k2q9x, and the app shows the session and the branch next to it.
A session works on several branches of one repository at once, each in its own worktree.
New worktrees start usable
A fresh worktree is a clean checkout, so Goodboy carries what it lacks. You tick the git-ignored files to copy into every worktree it creates, and a secret stays unticked until you choose it. The setup command is prefilled from the lockfile, such as pnpm install, and it never runs until you click Run.
A session branches from the latest commit
A repository with no commit yet holds sessions back, because a session branches from the latest commit. The board offers Make the first commit, which shows what goes in before it happens.
Clean up the folders you no longer need
Storage lists the worktree folders of archived, deleted or gone sessions with their size, and marks the ones that are safe to remove. Goodboy proposes and never removes by itself: nothing goes until you click, and Undo puts the folders back.
Common questions
Can two worktrees use the same branch?
Not by default. Git refuses to check out one branch in two worktrees at once, which is why every agent works on its own branch.
Does a worktree copy the whole repository?
No. It adds a working folder and shares the history of the repository with the main checkout, so it costs the size of the files and not the size of a clone.
Do agents change my open checkout?
No. In a git repository the agents edit in their own worktrees, so your checkout and its uncommitted changes stay as you left them.
Does Goodboy delete worktrees on its own?
No. Storage shows which folders are safe to remove and removes them only when you click.
Keep reading
This guide is part of What is an agentic development environment (ADE)?
- How to run multiple coding agents in parallelOne session for each goal, a stage board for all of them and cards that wait on you.
- Make changes across several repos in one agent sessionOne goal across several repos, with a branch and a pull request for each.
- Fix pull request review comments with AICheck the comments, press Fix, read each result and push once.
Let Goodboy run the worktrees
Install it, add a repository and start a session. Each branch the agents work on gets its own worktree.