How to Fix Git’s “Stopping at Filesystem Boundary” Error

“Stopping at filesystem boundary” means Git could not find a repository before its upward search reached a filesystem boundary. Usually, the fix is to run your command inside the correct checkout; enable cross-filesystem discovery only when the intended repository is above a mounted directory. Use the symptoms below to choose the right fix rather than changing settings unnecessarily.

Symptom Likely Cause Fix
Git works in your project folder but fails elsewhere The command is running outside the checkout Change to the project directory
Project files exist, but Git cannot recognize the project root Missing repository metadata, an archive download, or an incomplete copy Restore the metadata or clone a fresh checkout
Git works at the repository root but fails inside a mounted subdirectory Repository discovery stops at the mount boundary Test cross-filesystem discovery
Git works on the host but fails inside a container The container cannot access the repository metadata Correct the workspace mount or clone inside the container
The error appears when opening a shell or updating Oh My Zsh A startup command is running outside a repository, or the framework checkout is incomplete Check the command’s working directory and the framework repository

What Git’s Filesystem Boundary Error Means

The full message typically looks like this:

fatal: not a git repository (or any parent up to mount point /mnt)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

The named path varies with your environment.

For a command that needs a repository, Git normally checks the current directory and then walks upward through its parents looking for repository metadata. It does not search sibling folders, descend into project folders, or look everywhere on the computer.

By default, that upward discovery stops at a filesystem boundary. The environment variable named in the error controls whether Git may continue across that boundary, as documented in the Git environment-variable reference.

A repository can live entirely on a mounted drive without needing any special setting. The boundary matters only when Git must cross it while searching for the repository.

The error identifies where Git stopped searching, not proof that crossing that boundary will find your repository.

How to Fix the Git Discovery Error

The commands below use Bash-compatible syntax, suitable for Bash, Zsh, and typical Linux or WSL terminals. Replace example paths with your actual paths.

Step 1: Check Where the Command Is Running

  1. Print the current directory:
    pwd
  2. List its contents, including hidden entries:
    ls -la
  3. Check whether Git can identify a working-tree root:
    git rev-parse --show-toplevel

If the last command prints the expected project path, repository discovery is working in this terminal. A failure elsewhere, such as an IDE task or container, means you need to inspect that process’s working directory and environment.

If the command fails, determine where the actual checkout is supposed to be. A missing .git entry in a source subdirectory is normal: it usually belongs at the checkout root.

Step 2: Run Git From the Intended Checkout

  1. Change to the project’s root directory:
    cd /path/to/project
  2. Check the repository:
    git status

If this succeeds, retry your original Git command from this directory. There is no need to enable wider discovery.

For scripts and tools that should not depend on the caller’s working directory, Git’s -C option provides an explicit location:

git -C /path/to/project status

If Git still fails at the supposed project root, investigate missing or broken metadata before changing discovery settings. A folder containing source code is not necessarily a Git checkout.

Step 3: Test Discovery Across the Boundary

Test cross-filesystem discovery only when you expect the intended repository’s metadata to be in a parent directory beyond the mount boundary.

For example, the repository metadata might be in /workspace/project/.git, while /workspace/project/data is a separately mounted filesystem. A Git command started inside data may need to cross the boundary to find the parent repository.

  1. Return to the directory where the original command failed, then run `GIT_DISCOVERY_ACROSS_FILESYSTEM=true git rev-parse –show-toplevel`.
  2. Allow wider discovery for one command:
    GIT_DISCOVERY_ACROSS_FILESYSTEM=true git rev-parse --show-toplevel
  3. Check the returned path carefully.

If the command prints the intended repository root, the boundary was the obstacle. If the command still fails, widening discovery has not found a usable repository. If git rev-parse –show-toplevel prints an unexpected ancestor repository, do not proceed with write operations against that repository.

This assignment affects only the command on that line. The command-scoped GIT_DISCOVERY_ACROSS_FILESYSTEM assignment does not change Git configuration or persist in your shell.

Step 4: Apply the Setting Only Where Needed

If the cross-filesystem discovery test returns the intended repository root, enable GIT_DISCOVERY_ACROSS_FILESYSTEM for the current shell:

export GIT_DISCOVERY_ACROSS_FILESYSTEM=true

Then verify the selected repository and its status:

git rev-parse --show-toplevel
git status

If both commands identify the intended checkout, retry your original command.

For persistence, add that export line to the startup file used by the relevant shell:

  • Interactive Bash: ~/.bashrc, including typical Ubuntu and WSL Bash terminals.
  • Interactive Zsh: ~/.zshrc.

Open a new terminal and run the verification commands again. Putting a line in a startup file does not change an already-running terminal, IDE, or service.

Prefer a narrowly scoped setting when possible. A task that intentionally works inside a mounted subdirectory may need it; every Git process on the machine usually does not.

Fix Missing or Moved Repository Metadata

Wider discovery cannot recreate missing Git history or make an unmounted directory visible.

At an ordinary checkout root, .git is usually a directory. Linked worktrees and submodules can instead have a .git file that points to metadata elsewhere. Do not assume that a .git file is damaged simply because it is not a directory.

A Downloaded Folder or Missing .git Directory

A source archive generally contains project files without the repository’s Git history. Copying a project without hidden files can produce a similar result.

If you want an existing remote repository, clone it into a separate destination. Replace the example URL and path:

git clone https://github.com/OWNER/REPOSITORY.git /path/to/new-checkout

Verify the new checkout:

git -C /path/to/new-checkout status

If the old folder contains local edits, keep it intact while copying the intended working files into the new checkout. Do not copy the old .git entry over the new metadata.

Review the resulting changes:

git -C /path/to/new-checkout status
git -C /path/to/new-checkout diff

Untracked files appear in the status output but not in an ordinary diff. Review those files separately.

A fresh clone recovers history available from the remote, not local-only commits from missing metadata. If those commits matter, preserve the original folder and look for a backup of its Git metadata before replacing anything.

Also, pulling from a remote URL is not a substitute for cloning: git pull needs an existing local repository.

A Genuinely New Project

If this folder has never been a repository and you intentionally want to create one, initialize it:

git init /path/to/project

Then verify it:

git -C /path/to/project status

That creates a new repository; it does not recover an old repository’s commits, branches, or remote configuration. Avoid using initialization merely to silence an error in an existing project.

A Moved Linked Worktree

A linked worktree’s .git file points to administrative data associated with its main repository. Moving directories outside Git can break that connection.

When the main repository still exists and a linked worktree has moved, repair the connection from the main checkout:

git -C /path/to/main-checkout worktree repair /new/path/to/worktree

Verify the moved worktree:

git -C /new/path/to/worktree status

The Git worktree documentation documents this repair operation. The worktree repair operation reconnects existing metadata; it cannot recover metadata that was deleted.

WSL, Dev Containers, and Shell Startup Errors

For Git failures in WSL, dev containers, or shell startup commands, check the failing process’s working directory, access to repository metadata, and environment variables.

Ubuntu and WSL

A checkout under a mounted Windows drive, such as /mnt/c or /mnt/d, does not inherently require cross-filesystem discovery. If its metadata is inside the checkout and accessible, Git should find it before reaching the drive’s boundary.

When the problem follows a move between filesystems:

  • Check that hidden metadata was included.
  • Check whether a .git file still points to an accessible location.
  • Confirm that the failing command runs inside the moved checkout.

If you use a Bash startup setting, edit the file in the relevant WSL distribution, not a Windows shell profile. Open a fresh WSL terminal, enter the project, and check it:

git status

A successful check in one distribution or terminal does not establish that another environment has the same checkout or exported variables.

Docker and JetBrains Dev Containers

A container sees its own filesystem and the mounts provided to it. It cannot discover a host repository merely by searching farther upward.

For example, mounting only a project’s src directory into a container leaves the checkout’s parent .git directory outside the container. Allowing boundary crossing cannot reach metadata that is not present.

To correct this:

  1. Configure the workspace mount to include the checkout root and its hidden metadata.
  2. For a linked worktree, ensure the metadata referenced by its .git file is also reachable. An ordinary clone inside the container is another option.
  3. Recreate or reopen the development environment so the mount change takes effect.
  4. Run these checks inside the container’s terminal:
    git rev-parse --show-toplevel
    git status
  5. Retry the failing IDE operation.

In a JetBrains dev container, a successful integrated-terminal check does not necessarily prove that every IDE-launched Git process has the same environment. If only the IDE operation fails, check its repository location and how the container process receives environment variables. A terminal startup file is not a universal environment configuration for GUI applications.

Zsh and Oh My Zsh Startup Errors

If opening Zsh produces repository errors, inspect startup commands that invoke Git. Repository-local configuration commands belong in a repository context; they should not run unconditionally whenever a shell opens.

Remove unintended repository-specific commands from ~/.zshrc, or make their intended working directory explicit. Open a new shell and verify that startup is quiet, then check your project:

git -C /path/to/project status

Oh My Zsh’s framework checkout is separate from your own projects. In a shell where Oh My Zsh has set $ZSH, inspect that checkout directly:

git -C "$ZSH" status

If this fails while your projects work, the framework checkout needs attention. Changing your project’s Git identity will not repair missing framework metadata, and enabling wider discovery will not restore it.

Confirm the Fix and Prevent Repeat Errors

Verify the result in the exact terminal, container, task, or IDE context that originally failed:

git rev-parse --show-toplevel
git status

A successful fix means:

  • The reported root is the repository you intended to use.
  • Git can read its status without the discovery error.
  • The original operation works in its original execution context.

For automation, set a deliberate working directory rather than relying on wherever a job happens to start. Keep environment changes scoped to the processes that need them.

Once the repository root is correct, retry the original operation. Treat any new error as a separate problem rather than making further discovery changes.

Frequently Asked Questions

How Can I Show the Variable’s Value in Bash?

Use this command to inspect the value exported to child processes such as Git:

printenv GIT_DISCOVERY_ACROSS_FILESYSTEM

If it prints nothing, no nonempty value was displayed; the variable may be unset or empty. A shell variable that has not been exported is not passed to Git.

Why Does Git Say “Invalid Key: core.git_discovery_across_filesystem”?

The discovery control is an environment variable, not a Git configuration key. Git configuration variable names do not allow underscores in that position, so the attempted key is rejected. Set the environment variable in the relevant shell or process environment instead of adding it to local or global Git configuration.

Should I Use Sudo to Fix the Filesystem Boundary Error?

No: this message describes repository discovery, not a request for elevated privileges. Running Git with elevated privileges can also change the environment or create files with unwanted ownership. If Git separately reports permission denied, troubleshoot access to the specific path without treating privilege escalation as a discovery fix.