How to fix fatal: '/path/to/worktree' already exists in Git
This error occurs when Git cannot create a worktree because the target directory already exists or is registered as an existing worktree. Fix it by removing the directory, pruning stale worktree references, or using the --force flag.
Quick fix
Fixes fatal: '/path/to/worktree' already exists
git worktree list- List existing worktrees
- Check if the directory actually exists
- Prune stale worktree references
- Properly remove an existing worktree
git worktree listfatal: '/path/to/worktree' already exists
What this error means
The "fatal: '/path/to/worktree' already exists" error occurs when you try to add a Git worktree at a path that Git believes is already in use. Git worktrees allow you to check out multiple branches simultaneously in separate directories, all sharing the same repository data. Git maintains a record of all worktrees in the `.git/worktrees` directory of your main repository. When you run `git worktree add <path>`, Git checks both whether the filesystem path exists AND whether it's already registered as a worktree. The error can occur if either condition is true. This safety mechanism prevents you from accidentally overwriting an existing worktree or creating conflicts when the same path is tracked twice. However, it can become problematic when a worktree directory was manually deleted without using `git worktree remove`, leaving stale references in Git's tracking files.
Typical symptoms
- git worktree add fails with 'fatal: path already exists'
- Cannot create worktree even after manually deleting the directory
- git worktree list shows paths that no longer exist on disk
- Attempting to add a worktree for a branch shows it's 'already checked out'
- Re-cloning the repository temporarily fixes the issue but it returns
Common causes
- Target directory already exists on the filesystem (most common)
- Worktree was manually deleted without using 'git worktree remove', leaving stale references
- Previous worktree at that path was not properly cleaned up
- Branch is already checked out in another worktree (related but different error)
- GIT_WORK_TREE or GIT_DIR environment variables are set incorrectly
- Filesystem permissions prevent Git from detecting the path state correctly
How to fix "fatal: '/path/to/worktree' already exists"
First, check what worktrees Git currently knows about:
git worktree listThis shows all registered worktrees with their paths and checked-out branches. Look for the path you're trying to use - if it appears here, Git already considers it an active worktree.
Example output:
/home/user/project abc1234 [main]
/home/user/project-feat def5678 [feature-branch]Verify whether the target path exists on your filesystem:
ls -la /path/to/worktreeIf the directory exists and you don't need it, remove it:
rm -rf /path/to/worktreeWarning: Make sure you don't have uncommitted changes in that directory before deleting it.
If the directory doesn't exist but Git still thinks it does, prune the stale references:
git worktree pruneThis removes administrative files for worktrees whose directories have been deleted. Use --dry-run to preview what would be removed:
git worktree prune --dry-runFor verbose output showing what's being cleaned up:
git worktree prune -vIf the worktree exists and you want to replace it, remove it properly first:
git worktree remove /path/to/worktreeIf the worktree has uncommitted changes, you'll need to force the removal:
git worktree remove --force /path/to/worktreeFor a locked worktree (e.g., on a portable device), use force twice:
git worktree remove --force --force /path/to/worktreeIf you're certain the path is safe to use, you can force Git to create the worktree:
git worktree add --force /path/to/worktree branch-nameThis overrides the safety check that prevents using an existing path. Use this when:
- The path exists but is empty
- You've verified no important data will be lost
- Git's tracking is out of sync with the filesystem
Note: --force does NOT override the check for a branch being checked out elsewhere. For that, you need --force twice.
Environment variables can cause Git to behave unexpectedly with worktrees:
echo $GIT_DIR
echo $GIT_WORK_TREEIf either is set, unset them and try again:
unset GIT_DIR
unset GIT_WORK_TREE
git worktree add /path/to/worktree branch-nameThis is especially common when running Git commands from within a git rebase -i session or custom Git hooks.
If the above steps don't work or you want a quick solution, simply use a different path:
git worktree add /path/to/worktree-2 branch-nameOr create it in a sibling directory of your main repository:
git worktree add ../my-feature feature-branchThis avoids the conflict entirely while still giving you a functional worktree.
Advanced notes
Understanding Git worktree internals: Git stores worktree metadata in .git/worktrees/<worktree-name>/. Each entry contains a gitdir file pointing back to the main repository. If you manually inspect or modify these files, you can sometimes fix issues that git worktree prune doesn't catch.
Locked worktrees: You can lock a worktree to prevent it from being pruned (useful for worktrees on removable drives):
git worktree lock /path/to/worktree --reason "On USB drive"
git worktree unlock /path/to/worktreeMoving worktrees (Git 2.17+): Instead of removing and re-adding, you can move a worktree:
git worktree move /old/path /new/pathDetached HEAD worktrees: If you don't want to create or check out a branch, use:
git worktree add --detach /path/to/worktree HEADBranch already checked out: If you see "fatal: 'branch' is already checked out at '/other/path'", this is a different but related error. Git prevents the same branch from being checked out in multiple worktrees to avoid commit conflicts. Use --force to override this (not recommended) or check out a different branch.
CI/CD considerations: In CI pipelines, worktrees can accumulate between runs. Add git worktree prune to your setup steps, or use unique paths per build to avoid conflicts.
Frequently asked questions
- What does "fatal: '/path/to/worktree' already exists" mean?
- The "fatal: '/path/to/worktree' already exists" error occurs when you try to add a Git worktree at a path that Git believes is already in use. Git worktrees allow you to check out multiple branches simultaneously in separate directories, all sharing the same repository data. git/worktrees directory of your main repository.
- How do I fix "fatal: '/path/to/worktree' already exists"?
- This error occurs when Git cannot create a worktree because the target directory already exists or is registered as an existing worktree. Fix it by removing the directory, pruning stale worktree references, or using the --force flag.
- What causes "fatal: '/path/to/worktree' already exists"?
- Target directory already exists on the filesystem (most common) Worktree was manually deleted without using 'git worktree remove', leaving stale references Previous worktree at that path was not properly cleaned up
- Is the "fatal: '/path/to/worktree' already exists" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Git Official Documentation
- ๐Git Documentation: git-worktree(Official Docs)
- ๐ฌ
- ๐ฌStack Overflow: Branch is already checked out at other location(Stack Overflow)
- ๐ฌStack Overflow: Git worktree prune - what it does?(Stack Overflow)
- ๐ฌGit Mailing List: worktree add already exists(Stack Overflow)