Fix "fatal: not a git repository"
Git says it can't find a repo where you're standing. Usually it's the wrong directory, a missing .git, or an ownership check.
Key takeaways
- Git prints fatal not a git repository when it walks up from your current directory and finds no .git folder.
- Run pwd and git rev-parse --show-toplevel to confirm where you are, then cd into the repo, run git init, re-clone, unset GIT_DIR, or initialise submodules.
- Dubious ownership needs a safe.directory entry.
On this page
Fix "fatal: not a git repository" by moving into the folder that actually contains .git: run pwd, then cd into your repo and retry. Git searches the current directory and its parents, never subfolders. If no repo exists, run git init or clone; if .git exists, check GIT_DIR, uninitialised submodules, and the safe.directory ownership check.
Verified against
Git 2.56.0, against the git-scm.com reference pages for git, git-config (safe.directory) and git-rev-parse. Checked October 2026.
You run git status, expecting the usual list of changed files, and instead git slaps you with:
fatal: not a git repository (or any of the parent directories): .git
This one trips up beginners and senior engineers alike, usually because git is telling the literal truth and we don't believe it. Git walks up from your current directory looking for a .git folder. It checks where you are, then the parent, then the parent of that, all the way to the filesystem root. If it never finds one, you get this error. That's the whole mechanism. Every fix below is just a different reason git couldn't find that folder.
The causes below are in the order we actually hit them, most common first.
You're in the wrong directory
This is the boring answer and it's right most of the time. You opened a new terminal, or a script cd'd somewhere, and now you're standing in a folder that has nothing to do with your repo.
Check where you are:
pwd
# /Users/kiril/Downloads
ls -la | grep git
# (nothing)
No .git here. Go to where your repo actually lives:
cd ~/projects/my-app
git status
# On branch main
# nothing to commit, working tree clean
Fixed. Before you do anything clever, run pwd and ls -la. We have wasted real minutes debugging git only to realise we were one directory too high.
The folder was never a repo
Sometimes there's genuinely no repository because you never made one. You created a folder, dropped some files in, and started running git commands as if it were already tracked.
ls -la
# total 8
# drwxr-xr-x 4 kiril staff 128 Jul 11 09:14 .
# drwxr-xr-x 20 kiril staff 640 Jul 11 09:10 ..
# -rw-r--r-- 1 kiril staff 42 Jul 11 09:14 main.py
No .git directory in that listing. If this folder should be a repo, initialise it:
git init
# Initialized empty Git repository in /Users/kiril/projects/thing/.git/
git add .
git commit -m "initial commit"
If it's supposed to be a clone of something remote, don't git init on top of it. Clone it fresh into a new folder instead.
You cloned into the wrong place, or .git got deleted
A close cousin. You cloned a repo, but the .git folder ended up somewhere you didn't expect, or someone (maybe a cleanup script, maybe you) deleted it.
The tell is that all your files are present and correct, but git acts like it's never seen them. That's because the working files and the .git metadata are separate things. Delete .git and you've got a plain folder full of files with no history.
ls -la
# your files are all here...
# but no .git directory
If you have a remote, the cleanest fix is to re-clone and copy your uncommitted work over:
git clone git@github.com:you/my-app.git /tmp/my-app-fresh
# then move any local-only changes into the fresh clone
Trying to resurrect a half-deleted .git is rarely worth it. Re-clone and move on.
You're above the repo, not inside it
Git only searches upward, never downward. If your repo is at ~/projects/my-app and you're sitting in ~/projects, git looks in ~/projects, then ~, then /, and finds nothing. It will never look into my-app for you.
pwd
# /Users/kiril/projects
git log
# fatal: not a git repository (or any of the parent directories): .git
cd my-app
git log
# commit 4f1a9c2 (HEAD -> main) ...
One cd down and you're back in business.
GIT_DIR is pointing somewhere wrong
Less common, but nasty when it happens. Git respects the GIT_DIR environment variable. If some script or a stray line in your shell profile exported it to a path that doesn't exist, git will look there and only there, ignoring the .git under your feet.
echo $GIT_DIR
# /some/old/path/.git
unset GIT_DIR
git status
# On branch main
If unsetting it fixes things, hunt down whatever set it. Check ~/.zshrc, ~/.bashrc, and any wrapper scripts you source.
A submodule that was never initialised
Clone a repo with submodules and the submodule folders show up empty. Step into one and run a git command, and you get the same error, because the submodule's .git link hasn't been populated yet.
cd libs/shared
git status
# fatal: not a git repository ...
cd ../..
git submodule update --init --recursive
# Submodule path 'libs/shared': checked out 'a1b2c3d'
Now the submodule has its git data and behaves.
"Detected dubious ownership": the ownership variant
This one wears a different mask. You'll see a message like:
fatal: detected dubious ownership in repository at '/repo'
To add an exception for this directory, call:
git config --global --add safe.directory /repo
The .git folder is right there, but git refuses to touch it because the directory is owned by a different user than the one running git. It's a security feature, added to stop a repo you don't own from executing config hooks as you. You hit it constantly in Docker containers, on mounted volumes, and after copying repos around with sudo.
If you trust the repo, add the exception git already suggested:
git config --global --add safe.directory /repo
Do not reach for safe.directory '*' to make it shut up everywhere. The git-config docs describe * as a way to "completely opt-out of this security check". Add the specific paths you trust. Git only honours safe.directory in global or system config, so putting it in the repo's own .git/config does nothing. A repo you don't own running config as you is a real attack path, as the GitSpawn config-hijack write-up shows. In a container, fixing ownership at the source is cleaner:
chown -R $(id -u):$(id -g) /repo
The filesystem-boundary variant
On a mounted volume you may see a slightly different message ending in Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). Git's docs say discovery does not cross filesystem boundaries by default. If your repo root really sits on a different mount than your working directory, either cd to the repo root or set the variable:
export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
git status
How to actually diagnose it
Two commands settle almost every case. First, confirm whether a .git exists nearby:
ls -la
Second, ask git where it thinks the repo root is:
git rev-parse --show-toplevel
# /Users/kiril/projects/my-app <- you're inside a repo
# or: fatal: not a git repository <- you're not
If --show-toplevel prints a path, you're inside a repo and the error was likely a stale terminal or a GIT_DIR issue. If it errors, you're genuinely outside one, so it's a directory or an init problem.
Questions people ask
Why does git say not a git repository when the .git folder exists?
Three usual reasons. A GIT_DIR variable in your environment points git at another path, so unset GIT_DIR and retry. You're on a mount boundary and git stopped searching, so cd to the repo root. Or the folder is a submodule whose git link was never populated, so run git submodule update --init --recursive from the parent repo. Ownership problems print "dubious ownership" instead.
How do I fix "detected dubious ownership" in a Docker container?
The repo on the mounted volume is owned by a different UID than the user running git inside the container. Either run git config --global --add safe.directory /path/to/repo inside the container for that one path, or make the ownership match with chown or by running the container as your host UID. Avoid safe.directory '*', which turns the check off for every repository.
What does "or any of the parent directories" mean?
It describes how git looks for a repository. Starting at your current directory, it checks for .git, then moves up one level at a time until it reaches the filesystem root or a mount boundary. It never looks down into subfolders. So running git from ~/projects fails even when ~/projects/my-app/.git exists. Run cd my-app first.
The call we'd make
Run pwd and ls -la before you theorise. The overwhelming majority of these are you standing in the wrong folder, and you'll spot it in two seconds instead of two minutes. If the .git is present but git still balks, check for the dubious-ownership message and GIT_DIR before you assume anything is broken. Save the re-clone for when the .git is truly gone, and never blanket-whitelist safe.directory '*' just to silence a warning that exists to protect you. For the wider set of git failures, keep our Git troubleshooting guide within reach.
Sources
Cite this article
Kiril Urbonas (2026). Fix "fatal: not a git repository". DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/fix-git-not-a-repository
[Fix "fatal: not a git repository"](https://www.devopsness.com/blog/fix-git-not-a-repository) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
AWS Security Best Practices Checklist (2026)
A practitioner's checklist for securing AWS, ordered by impact so you fix the things attackers actually exploit first.
Best Practices: GitHub Actions Pipeline Reliability
Our CI was 73% green at the worst point. People trusted it less than coin flips. Six things we did to get to 96%, in rough order of impact.
DevOps Engineer Roadmap 2026: What to Learn, in Order
Most DevOps roadmaps are a wall of logos. This one is an order of operations, with a project that proves each stage and the topics you can safely skip in year one.
You might have missed
Evergreen posts worth revisiting.