Skip to content
  1. LuzineDebug
  2. Git & GitHub
  3. fatal: not a git repository (or any of the paren…
Git & GitHub Beginner ≈ 3 min to fix

Fix "fatal: not a git repository (or any of the parent directories): .git"

Error message
fatal: not a git repository (or any of the parent directories): .git
  • fatal: not a git repository (or any parent up to mount point /)
  • Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
  • fatal: not a git repository: /home/user/project/.git/worktrees/feature
  • fatal: not a git repository: ../.git/modules/lib
In short

Git cannot find a .git folder in the current directory or any of its parents: you are not inside a repository. Move into the project folder (cd my-project), or create the repository with git init or git clone.

Be the first to confirm this fix

What this error means

Almost every Git command (status, add, commit, push…) works on a repository. To find it, Git starts from the current folder and walks up to the root of the disk looking for a .git folder (or a .git file for worktrees and submodules). If it finds none, it stops with this message. The "not a git repository: path" form means something else: a .git exists but points to a folder that no longer exists (deleted worktree, moved submodule) or the GIT_DIR variable targets a wrong path.

Common causes

  1. Wrong folder: the terminal is open in your home folder or in the parent folder, not in the one created by git clone.
  2. Repository never initialised: the project was downloaded as a ZIP or created by hand, without git init.
  3. .git folder missing: deleted by mistake, not copied (it is hidden), or excluded by .dockerignore during a Docker build that calls git.
  4. Broken worktree or submodule: the .git file contains gitdir: … pointing to a path that no longer exists.
  5. GIT_DIR or GIT_WORK_TREE variable set wrongly in the shell or a script.

Step-by-step fix

  1. Check where you are

    Print the current folder and its content, hidden files included. In Windows PowerShell, use Get-Location and Get-ChildItem -Force.

    bash
    pwd
    ls -la
    git rev-parse --show-toplevel
  2. Move into the repository folder

    git clone creates a subfolder named after the repository: go into it before any other Git command.

    bash
    git clone [email protected]:user/repo.git
    cd repo
    git status
  3. Create the repository if it does not exist

    For a project not yet tracked by Git, initialise it at its root, then link it to your remote repository.

    bash
    cd /path/to/project
    git init
    git add .
    git commit -m "Initial commit"
    git remote add origin [email protected]:user/repo.git
  4. Broken worktree or submodule

    For a moved worktree, git worktree repair (run from the main repository) recreates the links and git worktree prune cleans up deleted ones. For a submodule, re-initialise it from the parent repository.

    bash
    cat .git
    git worktree repair /path/to/worktree
    git worktree prune
    git submodule update --init --recursive
  5. Check GIT_DIR and GIT_WORK_TREE

    If one of these variables is set, Git no longer looks for the repository automatically. Unset them in the current shell, then remove them from your profile or the script that sets them.

    bash
    env | grep ^GIT_
    unset GIT_DIR GIT_WORK_TREE
  6. In a Docker build or CI

    The .git folder is often excluded from the image (and that is better). Instead of calling git in the Dockerfile, pass the value you need as a build argument.

    bash
    docker build --build-arg GIT_SHA=$(git rev-parse --short HEAD) -t myapp .
    # Dockerfile:
    # ARG GIT_SHA
    # ENV GIT_SHA=$GIT_SHA

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Open your editor’s integrated terminal from the project folder: it starts in the right place.
  • Show the Git branch in your prompt (Oh My Zsh, Starship, posh-git): you instantly see whether you are in a repository.
  • Never delete the .git folder to clean up a project: the whole local history goes with it.

Frequently asked questions

Why can’t I see the .git folder?

It is hidden. Show it with ls -la (macOS, Linux), Get-ChildItem -Force (PowerShell), Cmd+Shift+. in Finder or "Hidden items" in Windows Explorer.

What does "Stopping at filesystem boundary" mean?

Git walked up the folders to another filesystem (mounted drive, Docker volume) without finding a repository and stops there for safety. Move into the repository folder rather than setting GIT_DISCOVERY_ACROSS_FILESYSTEM.

Why does the error appear with composer or npm?

A script or tool (Husky hooks, version computed from Git) runs a git command in a folder that is not a repository. Run the install from the repository root, or initialise it with git init.

Useful tools for this error

More Git & GitHub errors

All Git & GitHub errors →