Skip to content
Latchkey

git worktree remove: Usage, Options & Common CI Errors

git worktree remove cleanly deletes a linked working tree and its bookkeeping.

After a parallel build finishes, remove tears down the extra worktree properly - unlike rm -rf, it also clears the repo-side metadata so listings stay accurate.

What it does

git worktree remove deletes the working directory of a linked tree and its administrative files under .git/worktrees, provided the tree is clean. It refuses to remove the main worktree.

Common usage

Terminal
git worktree remove ../feature
git worktree remove --force ../feature   # even if dirty
git worktree prune                       # clean up stale entries
git worktree prune -n                    # dry run

Options

Flag / subcommandWhat it does
<path>Remove the worktree at path
-f / --forceRemove even with local changes (twice if locked)
pruneDrop metadata for already-deleted trees
prune -nShow what prune would remove

Common errors in CI

fatal: '<path>' contains modified or untracked files, use --force to delete it - the tree is dirty; pass --force when you are sure. A locked worktree needs --force twice. If you deleted the directory with rm instead, the entry lingers until git worktree prune.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →