Skip to content
WorktreeWise
#git#troubleshooting#locking#worktree

Worktree locked and cannot remove

W

WorktreeWise Engineering Team

Updated Sep 2026•5 min read
⚡

TL;DR: The 30-Second Summary

A worktree becomes locked when `git worktree lock` is executed or when an administrative lock file is created in `.git/worktrees/<name>/locked`. Locked worktrees cannot be removed or pruned. Inspect the lock reason with `git worktree list --porcelain` and unlock with `git worktree unlock <path>`.

The Real-Life Scenario

“A CI maintenance job attempts to clean up old build worktrees, but Git halts: `fatal: '/builds/preview-42' is locked: mounted on network NFS share`. The worktree was locked to prevent accidental pruning during maintenance.”

Git worktree locking is an intentional safeguard designed for removable storage, network mounts, and long-running background tasks. When locked, Git refuses to remove, move, or prune the worktree until it is explicitly unlocked.

Why Worktrees are Locked

When a worktree is placed on an external SSD or network volume that might be unmounted, `git worktree prune` could mistakenly assume the folder is missing and delete its administrative metadata. Locking prevents this.

What you see in the terminal:

terminal output
$ git worktree remove /builds/preview-42
fatal: '/builds/preview-42' is locked: mounted on network NFS share
🔍

Under the Hood: Git Plumbing & Architecture

Locking is represented by a simple text file: `.git/worktrees/<name>/locked`. The text inside the file is the reason provided when the lock was created. As long as this file exists, `git worktree remove` and `git worktree prune` treat the worktree as immutable.

Quick Command Recipes

Copy and adapt these commands directly in your terminal:

Inspect lock status and reason

Displays `locked <reason>` for any locked worktrees in the repository.

bash
git worktree list --porcelain

Unlock a worktree

Removes the `.git/worktrees/<name>/locked` file, restoring normal operations.

bash
git worktree unlock /path/to/worktree

Lock with a custom reason

Protects a worktree from accidental removal or automatic pruning.

bash
git worktree lock --reason 'reviewing production bug' /path/to/worktree
TUTORIAL

Step-by-Step Practical Walkthrough

Follow these verified steps to safely resolve the issue and guarantee that your filesystem and Git references are in sync.

1

Check why the worktree is locked

Run porcelain list to inspect the lock reason.

terminal
git worktree list --porcelain
Expected Output:
worktree /builds/preview-42
HEAD 94a11bc...
branch refs/heads/preview-42
locked mounted on network NFS share
2

Unlock the worktree

Run the unlock command to release the administrative lock.

terminal
git worktree unlock /builds/preview-42
3

Remove the worktree if needed

Now that it is unlocked, normal removal works without errors.

terminal
git worktree remove /builds/preview-42

Edge Cases & Advanced Scenarios

Lock file left behind after a machine crash

If `git worktree unlock` fails due to filesystem errors, you can manually delete the `.git/worktrees/<name>/locked` file.

bash
rm .git/worktrees/preview-42/locked
⚠️

Common Mistakes to Avoid

❌ Mistake: Passing `--force` to `git worktree remove` expecting it to bypass locks

Why it causes trouble: Even `--force` does NOT override an active worktree lock in Git.

What to do instead: You must run `git worktree unlock` first.

✓

Verification Checklist

  • ✓`git worktree list` no longer displays `locked` next to the worktree entry
  • ✓Removal and pruning execute without lock warnings
💡

Senior Engineering Tips

  • ★WorktreeWise displays a clear padlock icon next to locked worktrees and allows toggling locks with a single click.

Key Takeaways

  • 01.Locking protects worktrees from accidental deletion and pruning.
  • 02.`git worktree remove --force` will not delete a locked worktree.
  • 03.Unlock using `git worktree unlock <path>`.
TOOL

How WorktreeWise Solves This Visually

WorktreeWise eliminates the manual friction and mental overhead of CLI flags. It displays real-time branch states, uncommitted modifications, active terminals, and lock statuses across all worktrees on a single visual dashboard.

WorktreeWise interface displaying locked worktree status and reason
WorktreeWise interface displaying locked worktree status and reason
W

WorktreeWise Engineering Publication

Written and curated by the core WorktreeWise team. We build developer tools that turn Git worktrees, workflows, and parallel AI coding agents into second nature.

Related Troubleshooting Guides

View all troubleshooting →