How to Fix “Fatal: Not a Git Repository”

Git shows fatal: not a git repository when a command is run outside a Git working tree or Git cannot find the repository metadata. Start by checking your current directory, then confirm that the project was cloned or initialized correctly.

Practice Git workflows →

1. Check where your terminal is

Git commands such as git status need to run inside a repository, or one of its subdirectories. Print your current directory and list its contents:

pwd
ls -la

If you are in the wrong folder, move into the project directory and retry. For example, replace my-project with the actual folder name:

cd path/to/my-project

2. Find the Git repository root

In a valid working tree, this command prints the repository root:

git rev-parse --show-toplevel

If it succeeds, use cd to move to that path or confirm that your editor opened the intended project. If it returns the same fatal error, Git does not recognize the current directory or any parent directory as a repository.

3. Check whether the project was cloned

A downloaded source archive may contain project files without Git history. If you need the repository and have its URL, clone it into a new folder:

git clone <repository-url>

Then enter the directory Git creates and run git status. Avoid cloning on top of existing project files unless you understand the destination and have backed up any work you need to keep.

4. Initialize Git only if this should be a new repository

If this is your own new project and it is not already a clone, you can create repository metadata in the project directory:

git init
git status

Do not run git init just to silence an error in an existing project. It creates a new local repository; it does not restore missing history or reconnect the directory to its original remote.

5. Check editor, terminal, and environment context

“Not a git repository” FAQ

Why does Git work in one folder but not another?

One folder is inside a Git working tree and the other is not. Move into the project or use git rev-parse --show-toplevel to confirm the repository root.

Does git init fix this error?

It creates a new repository in the current directory, but is only appropriate if you intend to start a new repository there. It does not recover a missing clone or connect an existing project to its previous history.

Learn Git Faster by Practicing

Reading is just the first step. Real learning happens when you practice.

Start Learning Git →