Knowledge
Git fatal: not a git repository
#Git
This error means you ran a git command somewhere git does not recognise as a repository. Usually you are in the wrong directory, or the repo was never initialised.
Published by Mark van Eijk on June 23, 2026 · 1 minute read
- About the error
- Why do I see this error
- Solution
- Check where you are
- Initialise a new repository
- Clone instead, if the project lives on a remote
- Find the repository root from a subdirectory
About the error
fatal: not a git repository (or any of the parent directories): .git
Git commands operate on a repository, identified by a .git directory. When you run a git command, git looks in the current directory and walks up through the parents searching for .git. If it never finds one, you get this error.
Why do I see this error
- You're in the wrong directory, outside the project, or one level above it.
- The directory was never initialised as a git repository.
- The
.gitdirectory was deleted (sometimes accidentally, sometimes by an over-broad clean). - You cloned into a subdirectory and are running git from the parent.
Solution
Check where you are
First confirm your location and whether a .git directory exists here:
pwd
ls -la # look for a .git entry
If you don't see .git, you're either in the wrong place or this isn't a repo. cd into the actual project directory:
cd ~/Sites/my-project
git status
Initialise a new repository
If this directory should be a repository but never was, create one:
git init
Clone instead, if the project lives on a remote
If the code already exists on GitHub and you just don't have it locally, clone it rather than init:
git clone git@github.com:you/my-project.git
cd my-project
Find the repository root from a subdirectory
If you're somewhere inside a repo but a parent got confused, this prints the top level (or errors if you're truly outside one):
git rev-parse --show-toplevel
If you recently saw refusing to merge unrelated histories and then this, a deleted or recreated .git directory is a likely common cause.
Subscribe to our newsletter
Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!
Related articles
Removing tracked files in Git that should have been ignored
This error means you ran a git command somewhere git does not recognise as a repository. Usually you are in the wrong directory, or the repo was never initialised.
Change casing of file or directory in Git
This error means you ran a git command somewhere git does not recognise as a repository. Usually you are in the wrong directory, or the repo was never initialised.