How to fix fatal: '/path' is not a working tree in Git

GitINTERMEDIATELOWUpdated May 20, 2026· 308 views

This error occurs when Git cannot find a valid working tree at the specified path. The fix usually involves navigating to the correct directory, fixing worktree configuration, or cleaning up stale worktree references.

Quick fix

Fixes fatal: '/path' is not a working tree

pwd
  1. Check your current directory
  2. Check if you're in a bare repository
  3. List and prune stale worktrees
  4. Check core.worktree configuration
git — error
pwd
fatal: '/path' is not a working tree

What this error means

A "working tree" (or work tree) in Git is the directory where your actual project files live—the source code, images, documentation, and everything else that makes up your project. This is separate from the `.git` directory, which contains Git's internal metadata, object database, and configuration. When Git reports that a path "is not a working tree," it means one of several things: you're inside a bare repository (which has no working tree by design), you're inside the `.git` directory itself, the working tree was moved or deleted but Git still has a reference to its old location, or the `core.worktree` configuration points to a non-existent or incorrect path. This error commonly appears when working with `git worktree` commands, when using deployment hooks that reference a separate work tree, or after moving or renaming repository directories. Understanding the difference between a bare repository, a working tree, and the `.git` directory is key to resolving this issue.

Typical symptoms

  • Git commands fail with 'fatal: this operation must be run in a work tree'
  • The error message shows a specific path that 'is not a working tree'
  • Commands like git status, git add, git checkout, or git stash fail
  • git worktree list shows entries pointing to non-existent directories
  • Deployment hooks or CI scripts fail when trying to access a worktree

Common causes

  1. Running Git commands inside the .git directory instead of the project root
  2. Working in a bare repository, which has no working tree by design
  3. The core.worktree configuration points to a deleted or moved directory
  4. A linked worktree was deleted without using 'git worktree remove'
  5. A .git file in a subdirectory points to a deleted worktree location
  6. The GIT_WORK_TREE environment variable is set to an invalid path

How to fix "fatal: '/path' is not a working tree"

1Check your current directory

First, verify you're not accidentally inside the .git directory:

bash
pwd

If your path ends with /.git or you're inside a bare repository (a directory ending in .git with no working files), navigate up:

bash
cd ..

To find your working tree root:

bash
git rev-parse --show-toplevel

If this fails with "fatal: not a git repository," you're not in any Git repository.

2Check if you're in a bare repository

Bare repositories don't have working trees—they only contain the .git contents. Check if your repository is bare:

bash
git rev-parse --is-bare-repository

If this returns true, you have a bare repository. To work with files, you need to either:

Clone it to create a non-bare repository:

bash
git clone /path/to/bare-repo.git /path/to/working-copy
cd /path/to/working-copy

Or use --work-tree for a single command:

bash
git --work-tree=/path/to/checkout --git-dir=/path/to/bare-repo.git checkout HEAD -- .
3List and prune stale worktrees

If you've been using git worktree, list all worktrees to find invalid ones:

bash
git worktree list

Entries marked as "prunable" point to non-existent directories. Clean them up:

bash
# Dry run first to see what would be removed
git worktree prune --dry-run

# Actually remove stale worktree entries
git worktree prune

This removes administrative files for worktrees that no longer exist on disk.

4Check core.worktree configuration

Git may be configured to look for a working tree at the wrong location. Check the current setting:

bash
git config core.worktree

If this shows an incorrect or non-existent path, fix or remove it:

bash
# Set the correct path
git config core.worktree /correct/path/to/worktree

# Or remove the setting entirely
git config --unset core.worktree

Also check your .git/config file directly:

bash
cat .git/config | grep worktree
5Look for stale .git files in subdirectories

Linked worktrees use a .git file (not a directory) that points to the main repository. If a worktree was deleted manually, this file may still exist and cause issues.

Search for these files:

bash
find . -name ".git" -type f 2>/dev/null

If you find a .git file pointing to a non-existent location, you can safely delete it:

bash
cat ./some-directory/.git
# Shows: gitdir: /path/to/deleted/worktree/.git

rm ./some-directory/.git
6Check environment variables

Environment variables can override Git's default behavior. Check if any are set:

bash
echo $GIT_WORK_TREE
echo $GIT_DIR

If these point to invalid locations, unset them:

bash
unset GIT_WORK_TREE
unset GIT_DIR

For persistent issues, check your shell configuration files (~/.bashrc, ~/.zshrc, etc.) for these variables.

7Properly remove a worktree

If you need to remove a linked worktree, use the proper Git command instead of deleting the directory manually:

bash
# Remove a clean worktree
git worktree remove /path/to/worktree

# Force remove if there are uncommitted changes
git worktree remove --force /path/to/worktree

# Remove a locked worktree
git worktree remove --force --force /path/to/worktree

After removal, the worktree entry is automatically cleaned from Git's administrative files.

8Verify the fix

After applying the relevant fixes, verify Git is working correctly:

bash
# Check you're in a valid working tree
git rev-parse --show-toplevel

# Verify worktree list is clean
git worktree list

# Test a basic command
git status

All commands should now work without the "not a working tree" error.

Advanced notes

### Bare Repositories and Deployment

Bare repositories are commonly used as central remote repositories (like those on GitHub or GitLab) and in deployment workflows. They contain only the Git metadata without any working files, which is why commands like git status don't make sense in them.

For deployment with a bare repository and separate work tree:

bash
# In a post-receive hook
GIT_WORK_TREE=/var/www/mysite git checkout -f

### Worktree vs Work Tree

Note that git worktree (the command for managing multiple working trees) and "work tree" (the directory with your checked-out files) are related but distinct concepts:

- Work tree: The single directory where files are checked out
- git worktree: A feature allowing multiple work trees from one repository

### Automatic Cleanup

Git automatically cleans up stale worktree entries during garbage collection. The timing is controlled by:

bash
git config gc.worktreePruneExpire

Default is "3 months ago." You can run cleanup manually anytime with git worktree prune.

### Locking Worktrees

If a worktree is on a removable drive or network share that's not always mounted, you can prevent it from being pruned:

bash
git worktree lock /path/to/worktree --reason "On removable drive"
git worktree unlock /path/to/worktree  # When done

Frequently asked questions

What does "fatal: '/path' is not a working tree" mean?
A "working tree" (or work tree) in Git is the directory where your actual project files live—the source code, images, documentation, and everything else that makes up your project. git directory, which contains Git's internal metadata, object database, and configuration. worktree configuration points to a non-existent or incorrect path.
How do I fix "fatal: '/path' is not a working tree"?
This error occurs when Git cannot find a valid working tree at the specified path. The fix usually involves navigating to the correct directory, fixing worktree configuration, or cleaning up stale worktree references.
What causes "fatal: '/path' is not a working tree"?
Running Git commands inside the .git directory instead of the project root Working in a bare repository, which has no working tree by design The core.worktree configuration points to a deleted or moved directory
Is the "fatal: '/path' is not a working tree" error serious?
It is a low-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading