fatal: not a git repository (or any of the parent directories): .git means Git
looked for a .git folder in your current directory and in every folder above
it, and found none. Either you are in the wrong folder, or the project was never made a
repository.
If the project already has a repository, cd into the folder that contains
.git and run the command again. If it is a new project, run
git init once in its top folder and Git will find it from then on.
The error
> git status
fatal: not a git repository (or any of the parent directories): .git
Why it happens
Every Git command except a few like git init and git clone first
has to find the repository it should work on. It starts in the current directory and
looks for a .git folder there. If there is none, it moves up one level and
looks again, and keeps climbing until it reaches the root of the drive. That climb is what
"or any of the parent directories" in the message refers to, and it is why you can run
git status from any subfolder of a project and still get an answer.
When the climb reaches the top without finding .git, Git stops with this
message. The usual causes are a terminal that opened in your home folder instead of the
project, a freshly unzipped download (an archive carries the files but not the
.git folder), or a project you created but never initialised. A deleted or
renamed .git folder produces the same message.
The fix
> git init
Initialized empty Git repository in C:/.../plain/.git/
> git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
The path in the git init line is shortened; nothing else changed. After
git init the same git status works, because the climb now stops
at the new .git folder. Run git init only when you really mean
to start a new repository: if the project already lives in one higher up, initialising a
second one inside it creates a nested repository that the outer one sees as a single
opaque folder. To check where you are first, git rev-parse --show-toplevel
prints the top folder of the repository you are in, or this same error when there is
none.
How it was reproduced
Git for Windows 2.45.2 on Windows 11, run from Windows PowerShell. An empty folder in a
scratch directory with no repository in it or above it; git status there
printed the error, and git init followed by the same git status
printed the empty-repository status shown above.
Frequently asked
- What does 'not a git repository (or any of the parent directories)' mean?
- Git searched the current folder and every folder above it for a .git folder and found none. You are either outside the project folder or the project has never been initialised as a repository.
- Should I run git init to fix 'not a git repository'?
- Only for a new project. If the code already belongs to a repository, cd into its folder instead; running git init in the wrong place creates a second, empty repository.
- Why does a downloaded ZIP of a repository give 'not a git repository'?
- A ZIP download contains the files but not the .git folder with the history. Use git clone with the repository URL to get a working repository instead.
More decoded errors in the Fixes category. New to
repositories? Your first repository
walks through git init, the first commit and what the .git
folder holds.