Errorgit

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

Errorgit
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.

Related in Errors