Fatal: Not a Git Repository: What It Means and How to Fix It
Git says "fatal: not a git repository" when it can't find a .git folder. Here's how to find the right folder, start a repository, and fix GIT_DIR, submodule and ownership problems.
By PC MomentUpdated 7 min read

You ran git status, git add or git commit and got:
fatal: not a git repository (or any of the parent directories): .git
Git couldn’t find a repository where you ran the command. Nine times out of ten you’re simply in the wrong folder: cd into your project folder and run the command again. If that doesn’t do it, the causes below cover the rest.
What causes “fatal: not a git repository”
Every Git repository has a .git folder (or a .git file pointing to one) at the top of the project. When you run a Git command, Git checks the current folder for it, then each parent folder in turn. If it reaches the top without finding one, you get this error.
That happens when:
- You’re in the wrong folder, often the parent folder of your project or a new terminal window that opened in your home folder.
- The folder was never made into a repository (no
git initorgit clone). - The
.gitfolder was deleted, moved, or never there, for example in a project downloaded as a ZIP. - The
GIT_DIRenvironment variable or--git-diroption points to the wrong place. - A submodule’s
.gitfile points to a repository folder that no longer exists.
A related message, detected dubious ownership in repository, comes from a security check about who owns the folder. It’s covered at the end.
| What you see | Likely cause | Fix |
|---|---|---|
Error ends with (or any of the parent directories): .git | Wrong folder, or the folder isn’t a repository | cd to the project (Fix 1), or git init / git clone (Fix 2) |
| Project came from a ZIP download | No .git folder at all | Clone the repository (Fix 2) |
| Error ends with a specific path | GIT_DIR or --git-dir points to the wrong place | Clear or correct it (Fix 3) |
Path contains .git/modules/ | Broken submodule .git file | Rebuild the submodule (Fix 4) |
detected dubious ownership in repository | Folder owned by another user account | Take ownership or add safe.directory (Fix 5) |
How to fix it
Fix 1: Go to the right folder
-
Check where you are:
pwdIn Git Bash, macOS or Linux this prints the current folder. In Windows Command Prompt, use
cdwith no arguments instead; in PowerShell,pwdworks too. -
Move into your project folder, the one that contains your code:
cd ~/projects/my-appReplace the path with your own. On Windows in Command Prompt or PowerShell, a path looks like
cd C:\Users\you\projects\my-app. If the project is on a different drive in Command Prompt, add/d(cd /d D:\projects\my-app) so the drive changes too. -
Confirm Git sees the repository:
git rev-parse --is-inside-work-treeThis prints
truewhen you’re inside a repository’s working folder. Outside one, you get the same “not a git repository” error.
Tip: Typing long paths is where typos creep in. Press Tab after the first few letters of a folder name to complete it; our Command Prompt shortcuts guide covers Tab completion and other time savers.
Tip: You don’t have to
cdat all.git -C ~/projects/my-app statusruns the command as if Git had been started in that folder.
If you’re not sure which folder is the repository, look for the .git folder. On Windows it’s hidden: Git for Windows marks the .git folder as hidden by default (the core.hideDotFiles setting). List it with:
ls -a
in Git Bash, or dir /a in Command Prompt. In File Explorer on Windows 11, select View > Show > Hidden items. On Windows 10, open View > Options > Change folder and search options, then on the View tab select Show hidden files, folders, and drives.
Fix 2: Create or clone the repository
If the folder really isn’t a repository yet, decide which situation you’re in.
Starting a new project from scratch:
git init
This creates an empty repository, a .git folder with its subfolders, in the current folder. To choose the name of the first branch, add -b, for example git init -b main. Running git init again in an existing repository is safe; the docs say it won’t overwrite what’s already there.
Working on a project that already exists on GitHub or another server:
git clone https://github.com/owner/repo.git
cd repo
The first command downloads the full repository, history included, into a new repo folder. The second moves you into it, which is where Git commands work. Forgetting that cd is a common way to hit this error right after cloning.
Note: A project downloaded with GitHub’s Download ZIP button is a snapshot. GitHub’s docs say snapshots don’t contain the repository history and recommend cloning if you want it. Git commands won’t work in the unzipped folder, so clone the repository instead of running
git initon top of the ZIP contents.
If you just ran git init on a new project and your first push fails with error: src refspec main does not match any, see how to fix src refspec main does not match any.
Fix 3: Check GIT_DIR and —git-dir
If the error includes a specific path, like this:
fatal: not a git repository: 'C:/old/path/.git'
Git was told exactly where the repository is and didn’t search for it. The GIT_DIR environment variable or the --git-dir option does that: it sets the repository path and turns off the normal folder search.
-
Check whether
GIT_DIRis set. In Git Bash, macOS or Linux:echo $GIT_DIRIn PowerShell, use
$env:GIT_DIR. In Command Prompt, useecho %GIT_DIR%(if it prints%GIT_DIR%back, it isn’t set). -
If it points to the wrong place, clear it for the current session. In Git Bash:
unset GIT_DIRIn PowerShell, use
Remove-Item Env:GIT_DIR. -
If it comes back every time you open a terminal, remove it from wherever it’s set: your shell profile, a script, or Windows environment variables. Also check any alias or script that passes
--git-dir.
Fix 4: Repair a broken submodule
Submodules (and extra worktrees created with git worktree) don’t have a .git folder. They have a small .git file containing a line like gitdir: ../.git/modules/lib that points to the real repository inside the main project. If that folder is gone, for example because the main project was copied without its .git folder, you see:
fatal: not a git repository: C:/projects/app/lib/../.git/modules/lib
To rebuild a broken submodule:
Important: The next step deletes the submodule’s folder. Copy out any changes you made inside it that aren’t pushed anywhere.
-
Go to the main project’s top folder (the one with
.gitmodules). -
Delete the broken submodule folder, here
lib:rm -rf lib -
Clone it again from the URL recorded in
.gitmodules:git submodule update --init--initinitializes any submodules that haven’t been set up yet and checks them out.
Fix 5: Dubious ownership and safe.directory
Since the security releases that fixed CVE-2022-24765 (Git 2.35.2, plus 2.30.3 through 2.34.2 for older versions), Git refuses to work in a repository owned by a different user account than the one running Git. The message starts like this:
fatal: detected dubious ownership in repository at 'D:/shared/project'
Git then adds a few lines of detail and suggests a git config --global --add safe.directory command for it. This can happen with a repository created by another account or by a tool running as a different user.
Important: This check protects you from running hooks and settings planted by another user. Only add an exception for repositories you trust.
The safer fix is to make your own account the owner of the folder, or to clone a fresh copy under your own user folder. If the shared repository is intentional, trust that one folder:
git config --global --add safe.directory D:/shared/project
This adds the path to your global Git settings. Git only reads safe.directory from protected configuration (system, global or command-line), never from a repository’s own config. Avoid setting it to *: that turns the ownership check off for every repository.
If it still doesn’t work
- Run
git rev-parse --git-dirfrom the folder. If Git finds a repository, it prints the path to it; if not, it shows the same error, which confirms the problem is the folder. - Make sure the command you’re running is a Git command meant for a repository.
git cloneandgit initwork anywhere; most others need a repository. - If your editor or IDE shows this error, check which folder it opened. Open the project’s top folder, the one containing
.git, not a copy of the project or an unrelated parent folder. - If the
.gitfolder was deleted and the project was never pushed anywhere, the history is gone. Check your backups or the Recycle Bin before runninggit initagain.
Once the repository is found, these guides help with the next steps: git push set upstream, git undo last commit, and more in the programming section.
Frequently asked questions
What does fatal: not a git repository mean?
Git looked for a .git folder in your current folder and every parent folder and didn't find one. In other words, the folder you're in isn't part of a Git repository.
Should I run git init to fix it?
Only if you want to start a brand-new repository in that folder. If the project already exists on GitHub or another server, go to your existing clone or run git clone instead, so you get its history and remote.
Why can't I see the .git folder on Windows?
Git for Windows marks the .git folder as hidden by default. Turn on hidden items in File Explorer, or run dir /a in Command Prompt or ls -a in Git Bash to list it.
Is running git init in an existing repository dangerous?
No. The git documentation says rerunning git init in an existing repository is safe and won't overwrite what's already there.
What does fatal: not a git repository with a path after it mean?
When the message ends with a path, Git was told exactly where the repository is, through GIT_DIR, --git-dir or a .git file, and that path doesn't hold a repository. Fix or remove whatever points to it.
Related guides

Programming
Error: src refspec main does not match any (and master): How to Fix It
Git can't push main or master because that branch doesn't exist locally yet. Make your first commit, match the branch name, and push again.
5 min read

Programming
Git Push --force-with-lease: The Safer Way to Force Push
What git push --force-with-lease does, how it differs from --force, when to use it after a rebase or amend, and why --force-if-includes makes it safer.
7 min read

Programming
Git Push Set Upstream: Fix "The Current Branch Has No Upstream Branch"
Fix "fatal: The current branch has no upstream branch" with git push -u, set tracking on an existing branch, and make Git set the upstream for you.
5 min read

Programming
Git Undo Last Commit: Reset, Revert, Amend and How to Get It Back
Undo your last Git commit the right way: keep the changes, throw them away, or reverse a commit you already pushed, plus how to recover from a bad reset.
7 min read

Programming
Could Not Load File or Assembly System.Web.Helpers: How to Fix It
Fix the System.Web.Helpers load error in ASP.NET MVC: restore the Microsoft.AspNet.WebPages package, match the binding redirect, and get the DLL into bin.
5 min read