How to Fix 'fatal: not a git repository' Error
In this tutorial, you'll learn about How to Fix 'fatal: not a git Repository' Error. We cover key concepts, practical examples, and best practices.
The Problem
You run git status or git add and get:
fatal: not a git repository (or any of the parent directories): .git
Git can't find the .git folder that stores your repository data.
Quick Fix
1. Initialize the repo if it doesn't exist
git init
Expected output:
Initialized empty Git repository in /home/user/project/.git/
Now add and commit your files:
git add .
git commit -m "Initial commit"
2. If the .git folder was deleted
You deleted or moved the .git folder by accident. Initialize a new repo and reconnect to remote:
git init
git remote add origin https://github.com/user/repo.git
git fetch
git reset --mixed origin/main
This keeps your files and restores the git history from remote.
3. If you're in a subdirectory
Some nested folders aren't git repos. Check you're in the right directory:
ls -la .git
If .git doesn't exist, navigate to the project root:
cd /path/to/project
Prevention
Always clone repos instead of downloading ZIP files. Use git init at project start before you begin coding.
Common Causes
| Cause | Fix |
|---|---|
Downloaded ZIP instead of git clone |
git init && git remote add origin <url> |
.git folder deleted |
Re-init and pull from remote |
| Opened wrong directory | cd to the project root |
| Running git in a mounted volume | Init git inside the project folder itself |
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro