This message appears when Git detects worktree administrative data pointing to directories that no longer exist. Learn how to prune stale worktrees or repair broken references.
When you see "Removing worktrees/<name>: gitdir file points to non-existent location", Git is telling you that a worktree's metadata in `.git/worktrees/` contains a `gitdir` file pointing to a directory that no longer exists on your filesystem. Git worktrees allow you to have multiple working directories attached to the same repository. Each worktree has a corresponding subdirectory in `.git/worktrees/` that tracks its location via a `gitdir` file. This file contains the absolute path back to the worktree's `.git` file. When that referenced location is missing (because the worktree was manually deleted, moved, or is on unmounted storage), Git flags it as "prunable." This message typically appears during `git worktree list --verbose` or `git worktree prune` operations. It's informational, not an error - Git is identifying stale references that can be safely cleaned up.
First, see what worktrees Git knows about and their status:
# List worktrees with verbose output to see prunable entries
git worktree list --verboseOutput will look like:
/home/user/project abc1234 [main]
/home/user/project-feature def5678 [feature]
/home/user/old-worktree (error: gitdir file points to non-existent location)The "(error: ...)" annotation indicates stale worktree data.
Before removing any data, see what Git would prune:
# Dry run - shows what would be removed without doing it
git worktree prune --dry-run --verboseThis outputs messages like:
Removing worktrees/old-worktree: gitdir file points to non-existent locationReview the list to ensure you're not about to remove references to worktrees you still need (e.g., on unmounted drives).
If you're satisfied the listed worktrees are truly gone, prune them:
# Remove stale worktree administrative data
git worktree prune
# Verify they're gone
git worktree listThis removes the subdirectories in .git/worktrees/ that point to non-existent locations. It's a safe operation that only affects metadata, not any actual worktree contents.
If the worktree still exists but was moved, use git worktree repair instead of pruning:
# From the main repository, repair links to a moved worktree
git worktree repair /new/path/to/worktree
# Or run repair from within the moved worktree
cd /new/path/to/worktree
git worktree repairThis updates both the gitdir file in .git/worktrees/<name> and the .git file in the worktree to reflect the new paths.
If the worktree is on removable storage (USB drive, external disk), lock it to prevent accidental pruning:
# Lock the worktree with a reason
git worktree lock /path/to/worktree --reason "On external USB drive"
# Later, when storage is connected, unlock it
git worktree unlock /path/to/worktreeLocked worktrees won't be pruned even if their gitdir points to a non-existent location.
For troubleshooting, examine the worktree metadata directly:
# List all worktree metadata directories
ls -la .git/worktrees/
# Check what path a specific worktree's gitdir points to
cat .git/worktrees/<worktree-name>/gitdirThe gitdir file contains the absolute path to the worktree's .git file. If this path doesn't exist, that's why Git marks it as prunable.
If git worktree repair doesn't work or you need manual control, edit the gitdir file:
# Update the path in the gitdir file
echo "/new/correct/path/to/worktree/.git" > .git/worktrees/<name>/gitdir
# Also update the .git file in the worktree itself
echo "gitdir: /path/to/main/repo/.git/worktrees/<name>" > /new/path/to/worktree/.gitBoth sides must be updated to maintain the bidirectional link between the main repository and the worktree.
### How Worktree Tracking Works
Each linked worktree has a corresponding subdirectory in .git/worktrees/. This directory contains:
- gitdir: Absolute path back to the worktree's .git file
- HEAD: The worktree's current HEAD reference
- index: The worktree's staging area
- locked (optional): Present if the worktree is locked, contains the lock reason
The worktree directory itself contains a .git file (not directory) with content like:
gitdir: /path/to/main/repo/.git/worktrees/worktree-nameThis bidirectional linking allows Git to find the main repository from the worktree and vice versa.
### Automatic Pruning During Garbage Collection
Git automatically prunes stale worktree data during garbage collection based on gc.worktreePruneExpire:
# Check current setting (default: 3 months)
git config gc.worktreePruneExpire
# Set a different expiration (e.g., never expire)
git config gc.worktreePruneExpire never
# Or expire immediately on gc
git config gc.worktreePruneExpire now### Worktree Prune vs. Worktree Remove
- git worktree prune: Removes administrative data for worktrees that no longer exist on disk
- git worktree remove <path>: Removes both the worktree directory and its administrative data
Always prefer git worktree remove when intentionally deleting a worktree. Use prune only for cleanup after accidental deletions or system failures.
### Relative Paths in Worktrees (Git 2.42+)
Git 2.42 added --relative-paths for worktree operations:
# Create worktree with relative paths (portable across machines)
git worktree add --relative-paths ../feature-worktree feature
# Convert existing worktree to relative paths
git worktree repair --relative-pathsRelative paths make worktrees more portable but can break if either directory is moved independently.
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