fatal: not a git repository
Why git says fatal: not a git repository, the real reasons it happens, and how to tell a wrong directory apart from a missing .git folder.
Last updated
fatal: not a git repository (or any of the parent directories): .git
What it means: You ran a git command in a directory that isn't inside a git-tracked project — git walked up from the current directory looking for a `.git` folder and found none.
Likely causes
Most probable first — with how to confirm.
- 1.You're simply in the wrong directory — check with `pwd` (or `cd` with no args on Windows) that you're inside the project folder, not one level above it or somewhere unrelated.
- 2.The repo was never initialized here — check for a `.git` folder with `ls -a` (macOS/Linux) or `dir /a` (Windows); if it's missing, this folder was never `git init`'d and no clone completed here.
- 3.The `.git` folder was deleted or moved, accidentally, by a cleanup script, or by a tool that shouldn't have touched it — check `git status` from where you expect the repo root to be.
- 4.You're inside what was meant to be a submodule but got cloned as a plain folder instead — check the parent repo's `.gitmodules` file.
Fixes
Safest first; destructive ones are called out.
- →`cd` into the correct project directory — the most common fix, and it changes nothing on disk.
- →If the repo really was never initialized, run `git init` for a brand-new project, or `git clone <url>` if it should have come from a remote.
- →If `.git` was deleted by accident and a remote copy exists, re-clone into a fresh folder rather than trying to reconstruct history locally.
- →For a submodule that cloned as a plain folder, run `git submodule update --init` from the parent repo instead of treating it as standalone.
Part by part
- fatal:
- git's severity marker for an error it cannot continue past. Anything after it stopped the command entirely.
- or any of the parent directories
- The important half. git searched upward from where you are to the filesystem root, so this is not just about the current folder.
- .git
- The directory it was looking for. Its presence is what makes a folder a repository; nothing else about the contents matters.
Common mistakes
git initCreates a brand new empty repository, which is right when you meant to start one and quietly wrong when you are simply in the wrong directory — you now have a nested repo that will confuse everything later.
git clone <url> in a directory that already has the projectReaching for a fresh clone when you were one cd away from the existing repository. Check where you are with pwd before assuming the local copy is gone.
git init inside an existing repository's subdirectoryProduces a repository nested inside another. Both appear to work, commits go to whichever .git is nearest, and the outer repo sees the inner one as an untracked directory it cannot enter.
Questions
How do I find the repository I meant?
git rev-parse --show-toplevel prints the root of the repository you are in, and fails with this same message if there is not one. Running it from a directory you expect to be inside a repo confirms or denies it immediately.
I ran git init by mistake. How do I undo it?
Delete the .git directory that was just created. Nothing else was changed — git init only adds that folder, so removing it returns the directory to exactly its previous state.
Why does it fail inside a submodule or worktree?
Both use a .git file pointing elsewhere rather than a .git directory. If that file's path is stale — usually after moving or copying the parent — git cannot follow it and reports the folder as not a repository.
Can a repository exist without a .git directory?
A bare repository has no working tree and holds the git data at its top level, which is why cd-ing into a bare repo and running ordinary commands behaves unexpectedly. Those are for pushing to, not working in.