git worktree remove: Delete a Worktree
When you are finished with a linked worktree, use git worktree remove to delete the working directory and clean up the internal metadata that links it to the main repository. This is the recommended way to remove a worktree — it is safer than manually deleting the directory because Git checks for uncommitted changes and updates its bookkeeping automatically.
Basic Usage
git worktree remove <worktree-path>The worktree-path is the directory of the linked worktree you want to delete. You can run this command from any worktree (including the main one) — it does not have to be run from inside the worktree being removed.
# List current worktrees to find the path
git worktree list
# Remove the worktree at ../feature-login
git worktree remove ../feature-loginAfter running this command, the ../feature-login directory is deleted and the branch it had checked out becomes available for checkout in other worktrees again.
Force Remove (--force)
By default, Git refuses to remove a worktree that contains modified tracked files or untracked files. This safety check prevents accidental data loss. If you are sure you want to discard those changes, use the --force flag:
git worktree remove --force ../feature-loginA second level of force (--force --force or -ff) is required if the worktree has submodules with uncommitted changes, or if the worktree is locked:
# Remove a locked worktree with changes
git worktree remove -ff ../locked-worktreeWarning: Force-removing a worktree permanently deletes any uncommitted changes in that directory. Commit or stash your work first if you need to keep it.
What Happens When You Remove a Worktree
Running git worktree remove performs the following steps:
- Safety check— Git inspects the worktree for modified tracked files and untracked files. If any are found, the command aborts unless
--forceis used. - Delete the working directory— The entire worktree directory (e.g.,
../feature-login) is removed from disk, including its.gitfile. - Remove administrative data— Git deletes the corresponding directory under
.git/worktrees/in the main repository, which contains the worktree's HEAD, index, and other per-worktree state. - Unlock the branch— The branch that was checked out in the removed worktree is no longer marked as "in use," so it can be checked out in another worktree.
# Before removal — administrative data exists
ls .git/worktrees/
# feature-login/
# After removal — it's gone
git worktree remove ../feature-login
ls .git/worktrees/
# (empty or other worktrees)Clean Up with git worktree prune
If a worktree directory was deleted manually (with rm -rf or a file manager) instead of using git worktree remove, the administrative data in .git/worktrees/ is left behind. These stale entries can cause confusing errors like "branch is already checked out" even though the worktree no longer exists on disk.
Use git worktree prune to remove these orphaned entries:
# Preview what would be pruned (dry run)
git worktree prune --dry-run
# Actually prune stale entries
git worktree pruneFor more details on pruning, see the git worktree prune tutorial.
Best practice: Always use git worktree remove instead of deleting directories manually. This ensures both the files and the metadata are cleaned up in one step.
Common Errors
"contains modified or untracked files"
Git will not remove a dirty worktree by default. Either commit or stash your changes, or use --force:
$ git worktree remove ../feature-login
fatal: '../feature-login' contains modified or untracked files, use --force to delete it
# Option 1: commit your changes first
cd ../feature-login && git add -A && git commit -m "WIP: save progress"
cd ../main-repo && git worktree remove ../feature-login
# Option 2: force remove (discards changes)
git worktree remove --force ../feature-login"cannot delete branch" after removal
Sometimes after removing a worktree, Git may still think the branch is checked out somewhere. This usually means stale administrative data needs to be pruned. Run git worktree prune to fix it. For a detailed walkthrough, see Troubleshooting: cannot delete branch.
$ git branch -d feature/login
error: Cannot delete branch 'feature/login' checked out at '../feature-login'
# Fix: prune stale worktree data, then delete the branch
git worktree prune
git branch -d feature/login"is not a working tree"
This error means the path you specified is not recognized as a linked worktree. Verify the correct path with git worktree list:
$ git worktree remove ../wrong-path
fatal: '../wrong-path' is not a working tree
# Check the actual paths
git worktree list