How to Fix: fatal: not a git repository
Find the correct repository directory, recover a missing .git folder, or initialize safely without creating a repository in the wrong place.
Git prints fatal: not a git repository (or any of the parent directories): .git when the current directory is outside a working tree. Usually you opened a terminal in the wrong folder. Less often, the .git directory was moved, deleted, or is inaccessible.
Diagnose before you initialize
Run these non-destructive checks:
pwd
git rev-parse --show-toplevel
git rev-parse --is-inside-work-tree
On PowerShell, Get-Location is the equivalent of pwd. If git rev-parse fails, list the current directory—including hidden files—and move upward or into the expected project folder. A normal non-bare repository has a .git directory or, in a linked worktree, a .git file pointing to Git metadata elsewhere.
Fix 1: change to the repository directory
If the repository exists somewhere else, change to its root and check it:
cd /path/to/project
git status --short --branch
This is the safest and most common fix.
Fix 2: clone a missing working copy
If you expected a clone but only have unrelated files, clone into a new empty directory. Do not clone over an unknown directory.
git clone https://example.com/owner/repository.git project-copy
cd project-copy
git status
Replace the example URL with the repository’s real remote.
Fix 3: initialize only a genuinely new project
Risk:
git initcreates new repository metadata. It does not reconnect files to an existing remote or restore lost history.
If this directory is intentionally a brand-new project, first confirm the absolute path and contents, then run:
git init
git status
Do not run git init merely to silence the error in a downloaded or copied project. If .git was deleted, recover it from backup or make a fresh clone and copy only your uncommitted files into that clone after reviewing differences.
Why parent directories matter
Git searches the current directory and its parents for repository metadata. It stops at filesystem boundaries unless configured otherwise. That is why the same command may work in project/src but fail in a sibling folder.
Use the essential Git commands cheat sheet to verify the repository state after recovery.