Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

fatal: not a git repository How to fix this Git error

This is the most common Git error. It means Git cannot find a .git folder in your current directory or any parent directory. Here is how to diagnose and fix it in seconds.

Error explained

What this error means

When you see fatal: not a git repository (or any of the parent directories): .git, Git is telling you it looked for a .git/ folder in your current directory and every parent directory above it, but found nothing.

The .git/ folder is the hidden directory that stores your entire repository: commits, branches, configuration, and history. Without it, Git has no repository to work with and every Git command will fail.

This error does not affect your source files. Your code is safe. You just need to tell Git where the repository is, or create one.

Why it happens

Most common

Wrong directory

You opened a terminal or IDE in a folder that is not your project root. Maybe you are in your home directory, the Desktop, or a parent folder that does not contain a .git/ directory. This is by far the most frequent cause.

Easy to miss

Repository not yet created

You created a new project folder but forgot to run git init or git clone. The folder exists but it is not a Git repository yet. Git needs to be explicitly initialized before it can track changes.

Rare but serious

The .git folder was deleted

Someone (or a script) accidentally deleted the .git/ folder. This removes all version history from the local machine. If the project exists on a remote like GitHub, you can recover by cloning again. Otherwise the history is lost.

How to fix it

Three solutions depending on your situation. Start with the first one, which fixes the problem in most cases.

Navigate to the right folder

Initialize a new repository

Clone from remote

How to prevent it

Always open the project root in your IDE

In VS Code, use File > Open Folder and select the directory that contains the .git/ folder. Opening a parent or sibling folder will cause this error in the integrated terminal.

Check your directory before running Git

Make a habit of running pwd before any Git command in a new terminal session. This takes one second and prevents confusion, especially when you have multiple projects open.

Push to a remote regularly

If your .git/ folder is ever accidentally deleted, having a remote backup on GitHub or GitLab means you can always recover the full repository with git clone.

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about this error

Never get stuck on a Git error again

GitQuest teaches you Git through hands-on practice. Understand every command, every error, every fix.

Start learning Git