Git Worktree Answers
Fixes and explanations for common git worktree errors and setup questions.
A git worktree is a second working directory attached to the same repository. Worktrees are how most tools isolate parallel coding agents, so their errors show up often. Each answer below covers one error or question.
Start with the "branch is already used by worktree" fix if Git refuses a checkout. For a first setup, read where to put worktrees. For problems that only show up with several agents, see the coding agents and Git answers.
Fix "fatal: branch is already used by worktree"
fatal: 'branch' is already used by worktree at '<path>' means another worktree has it. Fix: give the new one its own branch with git worktree add -b.
Remove a Locked Git Worktree
Fix fatal: cannot remove a locked working tree. Unlock it or force removal with git worktree remove -f -f, and prune worktrees whose directory is gone.
Worktree or Clone to Review a Pull Request?
Worktree or fresh clone to review a pull request? Use a detached git worktree on the PR head. It is faster than a clone and leaves your branch alone.
Should Git Worktrees Go Inside the Repo or Next to It?
Put git worktrees next to the repository, not inside it. A nested worktree shows up as untracked and git add -A stages it as an embedded repository.
How to Use git worktree add for a New or Existing Branch
git worktree add <path> <branch> checks out an existing branch in a new directory. Add -b <name> to create a new branch for the worktree.
Git Worktree vs Branch: What Is the Difference?
Git worktree vs branch: a branch is a pointer to a commit, a worktree is a directory where a branch is checked out. Use worktrees to work on two at once.
Git Worktree Prune or Remove: Delete a Worktree Cleanly
Delete a Git worktree with git worktree remove, then git branch -d. If you already deleted the folder, git worktree prune clears the stale entry.
Cursor Worktrees: Run a Cursor Agent in a Git Worktree
Cursor worktrees: Cursor, now Grok Build, runs agents in Git worktrees from the Agents Window, the /worktree command or grok -w, with setup in worktrees.json.
Codex Worktrees: Run Codex CLI or the App in a Git Worktree
Codex worktrees: start Codex CLI in a managed Git worktree with codex --worktree or /worktree, or pick Worktree in the Codex desktop app.
OpenCode Worktrees: Run OpenCode in a Git Worktree
OpenCode worktrees: OpenCode v2 creates Git worktrees natively. Pick New worktree for a session in the desktop app, or press Ctrl+N in the TUI.
How to Read git worktree list Output
git worktree list shows each worktree's path, commit and branch, and marks locked and prunable ones. Use --porcelain -z in scripts.
Git Worktree VSCode Guide: Create, Open and Delete Worktrees
Git worktree in VSCode: create one from the Source Control Repositories view, open it in a new window, and delete it with Git: Delete Worktree.
Zed Worktrees: Create and Switch Git Worktrees in Zed
Zed worktrees: open the worktree picker from the title bar or git: worktree to create, switch and delete Git worktrees, and run agents in them.
GitHub Copilot Worktrees: Run Copilot in a Git Worktree
GitHub Copilot worktrees: start Copilot CLI with copilot --worktree or /worktree, or pick New worktree in the Copilot app or VS Code.