Git Worktree Checkout: Work on Multiple Branches
One of the primary uses of git worktree is checking out multiple branches simultaneously. Instead of switching branches in a single working directory, you create a separate worktree for each branch you need. Each worktree has its own directory, index, and HEAD, so you can work on all of them at the same time without conflicts.
Checkout an Existing Branch
To check out a branch that already exists locally into a new worktree, pass the branch name as the second argument to git worktree add:
# Check out the existing "feature/auth" branch in a new worktree
git worktree add ../feature-auth feature/auth
# The new worktree is ready to use
cd ../feature-auth
git status
# On branch feature/authThe branch must not already be checked out in another worktree. Git enforces this rule to prevent two working directories from simultaneously modifying the same branch, which could cause index corruption.
Checkout a Remote Branch
If the branch exists on a remote but not locally, fetch the refs first and then create a worktree. Git will automatically set up tracking if a unique remote branch matches the name:
# Fetch the latest refs
git fetch origin
# Create a worktree tracking the remote branch
git worktree add ../review origin/feature/review
# Git creates a local branch "feature/review" tracking the remote
cd ../review
git branch -vv
# * feature/review abc1234 [origin/feature/review] Latest commit messageIf you want the local branch name to differ from the remote branch name, use the -b flag:
git worktree add -b my-review ../review origin/feature/reviewCheckout and Create a New Branch
Use the -b flag to create a new branch and check it out in a single command. This is the most common workflow for starting new feature work:
# Create a new branch "feature/payments" based on main
git worktree add -b feature/payments ../payments main
# The new branch is created and checked out
cd ../payments
git log --oneline -1
# abc1234 (HEAD -> feature/payments, main) Latest main commitIf you omit both the -b flag and the branch name, Git automatically creates a new branch named after the last path component:
# Git creates a new branch named "payments" automatically
git worktree add ../paymentsDetached HEAD Checkout
Sometimes you want to check out a specific commit, tag, or ref without creating or switching to a branch. Use the --detach flag for this:
# Check out a specific tag in detached HEAD mode
git worktree add --detach ../v2-debug v2.0.0
# Check out a specific commit
git worktree add --detach ../bisect-wt abc1234This is useful for debugging a specific release, bisecting a regression, or comparing behavior across versions. Since no branch is checked out, the detached worktree does not block any branch from being used elsewhere.
# Verify the detached state
cd ../v2-debug
git status
# HEAD detached at v2.0.0The "Already Checked Out" Error
The most common error when checking out branches in worktrees is:
$ git worktree add ../second-main main
fatal: 'main' is already checked out at '/home/user/project'Git prevents the same branch from being checked out in two worktrees simultaneously. This is a safety feature — if two worktrees modified the same branch, they would overwrite each other's index and staging area.
Solutions to this error:
- Create a new branch based on the target branch instead:
git worktree add -b feature/new ../new-feature main - Use
--detachto check out the same commit without a branch:git worktree add --detach ../main-copy main - If the other worktree was deleted but not properly removed, prune the stale entry:
git worktree prune git worktree add ../second-main main
For a detailed guide on resolving this error, see Troubleshooting: already checked out.