git worktree remove deletes a linked worktree's directory and Git's record of it in one step. It is the counterpart of git worktree add, and the way the git-worktree manual tells you to finish with a worktree.
It deletes less than people expect (the branch stays) and more than some expect (ignored files such as node_modules and .env go without a warning). This guide covers the command, the --force rules, deleting the branch, cleaning up after a worktree folder was deleted by hand, and removing worktrees in bulk once a batch of coding-agent sessions is done.
Syntax
git worktree remove [-f] <worktree>
git worktree prune [-n] [-v] [--expire <expire>]<worktree> is the worktree's path, relative or absolute. If the last part of the path is unique among your worktrees, that is enough: with worktrees at ../wt/fix-login and ../wt/fix-cache, git worktree remove fix-login works. Run it from the main worktree or any other linked one.
remove, prune or rm -rf?
| You want to | Run | What happens |
|---|---|---|
| Finish with a worktree that still exists | git worktree remove <path> | Deletes the directory and its entry in .git/worktrees/. Refuses if it has uncommitted or untracked work. |
| Clean up after deleting the folder yourself | git worktree prune | Deletes the entries in .git/worktrees/ whose directories are missing. Touches no files on disk. |
Delete the folder with rm -rf or your file manager | Avoid it | The files go, but Git still thinks the worktree exists: its branch stays checked out until you prune. |
Remove a worktree
git worktree list
# /home/me/code/app c5c2233 [main]
# /home/me/code/app-hotfix 8cf6120 [hotfix]
git worktree remove ../app-hotfix
git worktree list
# /home/me/code/app c5c2233 [main]That deletes the ../app-hotfix directory and .git/worktrees/app-hotfix. Commits you made there are safe: they live in the shared object database, on the hotfix branch, which remove leaves alone.
What it checks first is narrower than it sounds. A worktree counts as clean when it has no modified tracked files and no untracked files. Ignored files don't count, so node_modules, build output, virtualenvs and any .env your .gitignore covers are deleted along with the directory without a prompt. Copy out any local config you want to keep before you remove the worktree.
You can rungit worktree remove .from inside a linked worktree and Git will delete it, leaving your shell in a directory that no longer exists.cdback to the main worktree first.
When it has uncommitted work: --force
$ git worktree remove ../app-hotfix
fatal: '../app-hotfix' contains modified or untracked files, use --force to delete itLook before you force it. git -C ../app-hotfix status shows what would be lost. Commit it, stash it (the stash is shared, so you can pop it in another worktree) or, if you really don't need it, delete it with one --force:
git -C ../app-hotfix status --short
git worktree remove --force ../app-hotfixA worktree with submodules also needs --force, even when it is clean.
When it is locked: unlock, or --force twice
A worktree locked with git worktree lock (or created with add --lock) is protected from remove, move and prune. It is usually locked because it lives on a removable or network drive, so check the reason before overriding it:
$ git worktree remove ../usb-build
fatal: cannot remove a locked working tree, lock reason: on the USB drive
use 'remove -f -f' to override or unlock first
git worktree unlock ../usb-build
git worktree remove ../usb-build
# or, in one go:
git worktree remove -f -f ../usb-buildgit worktree list marks locked worktrees as locked, and git worktree list -v prints the reason.
Delete the branch too
Removing a worktree never deletes its branch. Once the worktree is gone the branch is free, and you delete it like any other:
git worktree remove ../app-hotfix
git branch -d hotfix # refuses if hotfix isn't merged
git branch -D hotfix # deletes it anyway
git push origin --delete hotfix # and the remote branch, if you pushed itgit branch -d checks that the branch is merged into its upstream, or into your current HEAD if it has none. A branch that was squash-merged or rebase-merged on the server won't look merged to Git, so -d refuses it; check the pull request before reaching for -D.
Order matters: while a worktree has a branch checked out, git branch -d refuses with cannot delete branch 'hotfix' used by worktree at '...'. Remove the worktree first.
Deleted the folder by hand? git worktree prune
If the directory is already gone, Git still has its entry in .git/worktrees/, and the worktree shows up as prunable:
$ git worktree list
/home/me/code/app c5c2233 [main]
/home/me/code/app-hotfix c5c2233 [hotfix] prunable
$ git worktree prune --dry-run --verbose
Removing worktrees/app-hotfix: gitdir file points to non-existent location
$ git worktree pruneprune only clears records for worktrees whose directories are missing; it never deletes files, and it skips locked worktrees. --dry-run (-n) shows what it would do, --verbose (-v) reports each removal, and --expire <time> limits it to entries older than that. Running git worktree remove on the missing path clears that one record too.
Until you prune, the stale record gets in the way: the branch counts as checked out, so git branch -d refuses it, and git worktree add refuses to reuse the path with is a missing but already registered worktree. Git also prunes on its own when git gc runs, for entries older than gc.worktreePruneExpire (see git-config for the default).
If the directory isn't deleted but moved, don't prune: rungit worktree repair <new-path>to reconnect it, or usegit worktree movenext time.
When git worktree remove refuses
Wording varies a little between Git versions; these are the cases:
| Error says | Why | Fix |
|---|---|---|
contains modified or untracked files, use --force to delete it | The worktree has uncommitted changes or new files. | Check git -C <path> status, then commit, stash, or remove with --force. |
| cannot remove a locked working tree | It was locked with git worktree lock. | git worktree unlock <path> first, or remove -f -f. |
| is a main working tree | You pointed it at the main worktree, which can't be removed. | Remove linked worktrees only. To get rid of the whole repository, delete its directory. |
| is not a working tree | The path doesn't match any registered worktree. | Copy the exact path from git worktree list; it may already have been removed. |
| Permission denied, or a file is busy | An editor, dev server or terminal still has files open there (common on Windows). | Close what is using the directory, then run the command again. |
Remove many worktrees at once
After a batch of parallel coding-agent sessions, or a week of reviews, worktrees pile up. Git has no remove-all command, but git worktree list --porcelain prints one worktree <path> line per worktree, main worktree first, which is easy to loop over. This removes every linked worktree that is clean, and leaves (with an error) any that has uncommitted work:
git worktree list --porcelain | sed -n 's/^worktree //p' | tail -n +2 |
while IFS= read -r wt; do git worktree remove "$wt"; done
git worktree pruneTo be more selective, keep only the worktrees whose branch has landed. This one assumes each agent worked in its own directory under ../wt on a branch started from origin/main:
git fetch origin
for wt in ../wt/*/; do
wt=${wt%/}
branch=$(git -C "$wt" symbolic-ref --quiet --short HEAD) || continue # skip detached
if git merge-base --is-ancestor "$branch" origin/main; then
git worktree remove "$wt" && git branch -d "$branch"
fi
done
git worktree pruneNeither loop passes --force, so a worktree with uncommitted work survives and you see why. Squash-merged branches aren't ancestors of origin/main and are skipped by the second loop; remove those by hand once you have checked their pull requests. Agent tools that create worktrees for you may also clean them up themselves, so check your tool's docs before scripting around it.
Frequently asked questions
Does git worktree remove delete the branch?
No. It deletes the worktree's directory and Git's record of it; the branch and its commits stay. Delete the branch afterwards with git branch -d <branch>.
Can I just delete the worktree folder?
You can, but Git keeps a record of the worktree, so its branch stays checked out and the path stays registered. Run git worktree prune afterwards, or use git worktree remove instead, which does both in one step.
Does git worktree remove delete ignored files like node_modules or .env?
Yes. Only modified and untracked files make it refuse; ignored files are deleted with the directory without a prompt. Copy out any local config you want to keep first.
What is the difference between git worktree remove and git worktree prune?
remove deletes a worktree that still exists, files and record together. prune only clears the records of worktrees whose directories are already gone, and never deletes files.
Can I remove the main worktree?
No. git worktree remove only removes linked worktrees, and refuses the main one with is a main working tree.
How do I remove all worktrees?
Loop over git worktree list --porcelain, skipping the first entry (the main worktree), and run git worktree remove on each, then git worktree prune. The loop is in the section on removing many worktrees above.
Related guides
- git worktree add: every form of the command, with examples
- git worktree vs branch: what each one is, and when to use a worktree
- Claude Code worktrees: run parallel sessions with --worktree
Sources
- git-worktree documentation (git-scm.com)
- git-branch documentation (git-scm.com)
- git-config: gc.worktreePruneExpire (git-scm.com)
More on worktrees in Git Worktrees, or browse all guides.




