Git: fatal: not a git repository

Fix the Git 'not a git repository' error when running commands outside a Git-initialized directory.

Git: fatal: not a git repository

Git produces "not a git repository" when a git command runs outside a directory containing a .git subdirectory.

When Git Produces This Error

Git displays fatal: not a git repository (or any of the parent directories): .git when running any git command in a directory that has not been initialized with git init or cloned with git clone.

What Causes "not a git repository" in Git

The current working directory and none of its parent directories contain a .git subdirectory. Git searches upward from the current directory to the filesystem root for .git.

How to Fix "not a git repository" in Git

  1. Navigate to the correct repository directory:

    cd /path/to/my-project
    git status
  2. If the directory should be a repository, initialize it:

    git init
  3. If the repository was cloned to a different location, find it:

    find / -name ".git" -type d 2>/dev/null