How to fix "fatal: not a git repository (or any of the parent directories)"
Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with Git 2.43.0, November 29, 2026.
Git can’t find a .git folder in the directory you’re in or any folder above it. Most of the time you’re in the wrong folder. Check where you are and whether Git sees a repo:
pwd
git rev-parse --show-toplevel
If the second command fails, cd into the project folder (the one that contains .git) and run your command again. If the project was never a Git repository, start one with git init, or clone the existing repo with git clone <url>.
We reproduced each version of the message below with Git 2.43.
The message and what it tells you
Run outside any repository, git status printed:
fatal: not a git repository (or any of the parent directories): .git
The exit code was 128, which scripts can check for. “Any of the parent directories” means Git walked up from your current folder to the root of the filesystem and found no .git anywhere. Any Git command that needs a repo (git status, git log, git remote add, git commit) fails the same way.
Two variants point to a specific path instead:
| Message | Cause |
|---|---|
fatal: not a git repository (or any of the parent directories): .git |
No .git found from here up |
fatal: not a git repository: '/tmp/nowhere' |
The GIT_DIR environment variable points to a folder that doesn’t exist |
fatal: not a git repository: .../.git/modules/lib |
A submodule or worktree’s .git file points to a folder that has moved or been deleted |
Fixes by cause
You’re in the wrong folder
This is the usual cause, especially right after git clone, which creates a new subfolder. Move into it:
git clone https://github.com/user/project.git
cd project
git status
You can also run a command against a repo without changing directory. git -C /path/to/project status works from anywhere.
The project was never a repository
Create one in the project’s top folder:
git init
git add .
git commit -m "Initial commit"
To connect it to an existing remote afterwards, add the remote. If that step fails, see remote origin already exists.
The .git folder was deleted or never copied
Copying a project folder without hidden files, or downloading a ZIP from GitHub, leaves out .git. In our test, deleting .git from a repo gave the standard message. If the code is on a remote, clone it fresh and copy any changed files across. If it isn’t on a remote, the history is gone, and git init starts a new one.
GIT_DIR is set
If an old shell session or script exported GIT_DIR, Git uses that instead of searching:
echo $GIT_DIR
unset GIT_DIR
A broken submodule or worktree link
Submodules and extra worktrees have a .git file (not a folder) containing a gitdir: line. If that target moved, Git prints the path it tried. In our test, deleting a submodule’s data from .git/modules made git status inside the submodule print fatal: not a git repository: /tmp/gt4/app/lib/../.git/modules/lib. Removing the submodule folder and running this from the main repo checked it out again:
git submodule update --init
Commit or copy out any work inside the submodule folder before you remove it. For a worktree whose folder was deleted, git worktree list marked it prunable and git worktree prune removed the stale entry.
Check whether you’re in a repo
In scripts, test first instead of letting a command fail:
git rev-parse --is-inside-work-tree
Inside a repo this printed true. Outside, it printed the same fatal: not a git repository line and exited with 128.
A similar error that isn’t this one
fatal: detected dubious ownership in repository at '/path' means Git found the repo but the folder belongs to another user, so it won’t use it. We reproduced it by changing the owner of a repo. Git suggests the fix itself:
git config --global --add safe.directory /path/to/repo
Only add folders you trust, since Git’s check exists to stop another user’s repo config from running commands as you. Git’s safe.directory documentation explains the setting.
FAQ
What does "fatal: not a git repository" mean?
Git looked for a .git folder in the current directory and every folder above it and didn't find one. Usually you're in the wrong folder. Less often the repo was never created, the .git folder was deleted, or GIT_DIR points somewhere that doesn't exist.
How do I fix the not a git repository error in VS Code?
VS Code runs Git in the folder you opened. Use File > Open Folder and open the project's top folder (the one containing .git), not a parent or a single file. If the project has no repo yet, the Source Control panel offers "Initialize Repository".
How do I fix it in GitHub Actions?
A job starts with an empty workspace. Add the actions/checkout step before any step that runs Git, and if a step changes directory, make sure it stays inside the checked-out folder.
Should I just run git init?
Only if the project has never been a repository. If it exists on GitHub or another remote, clone it instead (or run git init and then add the remote and fetch). Running git init in the wrong folder creates a new, empty repo that has nothing to do with your project.
