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.
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.
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.
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.
warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server