fatal: not a git repository (or any of the parent directories) β Fix
fatal: not a git repository (or any of the parent directories): .git
This error means Git canβt find a .git folder in your current directory or any parent directory. It happens when you run any git command β git status, git branch, git log, git commit, git push β outside of a repository. Youβre either in the wrong directory, the repo wasnβt initialized, or the .git folder is missing.
Fix 1: Youβre in the Wrong Directory
The most common cause. You cdβd somewhere that isnβt a git repo.
# Check where you are
pwd
# Navigate to your project
cd ~/projects/my-app
# Verify it's a repo
ls -la .git
Fix 2: Initialize a New Repo
If this is a new project that hasnβt been initialized:
git init
This creates the .git folder. Then add your files:
git add -A
git commit -m "Initial commit"
Fix 3: Clone Instead of Download
If you downloaded a ZIP from GitHub instead of cloning, thereβs no .git folder.
# Delete the downloaded folder and clone properly
git clone https://github.com/user/repo.git
Fix 4: The .git Folder Was Deleted
If someone (or a script) accidentally deleted .git:
# If you have a remote, re-clone
git clone https://github.com/user/repo.git temp-clone
mv temp-clone/.git .
rm -rf temp-clone
# Then check status
git status
If you donβt have a remote, the history is gone. Initialize fresh:
git init
git add -A
git commit -m "Re-initialize repository"
Fix 5: Submodule Issues
If youβre inside a git submodule that wasnβt initialized:
# Go to the parent repo
cd ..
# Initialize submodules
git submodule init
git submodule update
Prevention
- Use
git statusbefore running git commands β itβll tell you if youβre in a repo - Use your terminal prompt to show the current git branch (most modern shells do this by default)
- Donβt delete
.gitfolders unless you know what youβre doing
Related resources
Related: Git Merge Conflict β How to Fix It Related: How to Undo the Last Git Commit Related: Fix: Git push rejected β non-fast-forward Related: Fix: Git detached HEAD state Related: Fix: Git permission denied (publickey)