🔧 Error Fixes

fatal: not a git repository — What It Means and How to Fix It


fatal: not a git repository (or any of the parent directories): .git

Git can’t find a .git folder in your current directory or any parent directory. You’re either not in a repo, or the repo is broken.

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 status before 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 .git folders unless you know what you’re doing