Skip to main content

How to Use git worktree add for a New or Existing Branch

git worktree add <path> <branch> checks out an existing branch. git worktree add -b <new-branch> <path> <start> creates the branch and the worktree together.

The Fix​

Create a new branch from main in a sibling directory:

git worktree add -b new-feature ../repo-new-feature main

Check out a branch that already exists:

git worktree add ../repo-feature feature

Git 2.43 prints what it did:

Preparing worktree (new branch 'new-feature')
HEAD is now at 54d33c8 init
Preparing worktree (checking out 'feature')
HEAD is now at 54d33c8 init

Then cd into the path and work as usual. git worktree list shows every worktree and its branch:

/src/repo 54d33c8 [main]
/src/repo-feature 54d33c8 [feature]
/src/repo-new-feature 54d33c8 [new-feature]

Other Forms​

CommandResult
git worktree add ../quick-fixNew branch quick-fix from HEAD, named after the directory
git worktree add ../repo-hotfix hotfixWhen only origin/hotfix exists, creates local hotfix tracking it
git worktree add --track -b fix ../repo-fix origin/hotfixNew branch fix that tracks origin/hotfix
git worktree add ../repo-review origin/hotfixDetached HEAD at that commit, no branch
git worktree add --detach ../repo-review HEADDetached HEAD, for builds or read-only review
git worktree add -B feature ../repo-feature mainCreates feature, or resets it to main if it exists

Passing a remote-tracking ref such as origin/hotfix gives a detached worktree. Pass the plain branch name, or use --track -b, when you want to commit and push from it.

Why It Fails​

-b refuses a name that already exists:

Preparing worktree (new branch 'feature')
fatal: a branch named 'feature' already exists

Drop -b to check out the existing branch, or use -B to reset it. Use -B only when you mean to throw away that branch's commits.

A branch can be checked out in one worktree at a time. Adding a branch that another worktree holds fails with fatal: 'feature' is already used by worktree at '<path>'. Fix "branch is already used by worktree" covers that error.

Put the path outside the repository, as in ../repo-feature. A worktree inside the main checkout shows up as untracked files there. Should Git worktrees go inside the repo or next to it? explains the trade-off.

How Treq Handles It​

Treq does not ask you to run git worktree add. It creates a managed workspace with its own working copy and branch under .treq/workspaces/, then starts your shell or agent in it. treq add does the same from the CLI.