Home·Error messages

git · Git

The message

fatal: not a git repository (or any of the parent directories): .git

What it means

There is no .git in this directory or in any directory above it, so git could not find a repository. It happens when you are standing one level above or below the repository, when a clone landed in a different folder, or when you never ran git init. Check where you are with pwd first, and use git init only if you truly mean to start a repository here. Running git init inside a subfolder of an existing repository creates a second, nested repository that quietly shadows the outer one, and from then on the files in that folder never enter the outer commits.

The fix

git init
Printed by
git
Git
29

Almost every git error is a refusal that means "doing that from this state would lose something"; fatal: means git stopped without changing anything, and the hint: lines under the first line usually carry the actual remedy.

Reading an error message

  • Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
  • If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
  • Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
  • The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
  • Before pasting a fix, check what it throws away. Some of these cannot be undone.

Common questions

Q. What does “fatal: not a git repository (or any of the parent directories): .git” mean?

There is no .git in this directory or in any directory above it, so git could not find a repository. It happens when you are standing one level above or below the repository, when a clone landed in a different folder, or when you never ran git init. Check where you are with pwd first, and use git init only if you truly mean to start a repository here. Running git init inside a subfolder of an existing repository creates a second, nested repository that quietly shadows the outer one, and from then on the files in that folder never enter the outer commits.

Q. How do I fix it?

git init — before running it, check the explanation above for what this command discards.

Q. Which tool prints this?

git. It sits under Git, and the message runs to 12 words.

Errors nearby