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

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

By Emily

You’ve probably just tried doing something in a command line tool of some kind if you’ve received the message “fatal: not a git repository (or any of the parent directories): .git“. In which case you’ve probably tried to run a git command in a folder which is not a git repo. Hence the ‘fatal not a git repository’ message. This will be because of one of these reasons:

  1. The folder has not been initialized as a git repo yet
  2. You are in the wrong folder!
  3. The .git file has been incorrectly edited

Check if the folder is a git repo

To check if your current folder is a git repo, try typing this:

git status

If you get the same message “fatal: not a git repository” then you’re definitely not in a git repo. In which case you will also need to check what folder you are in, for that please read on.

Find out which folder you are currently in

To find out which folder your command line tool is in currently, type:

pwd

… and it will simply tell you which folder you’re in.

Use pwd command to see current folder name if you get the fatal not a git repository message

So now if you are not in the right folder, navigate to the correct folder and try again.
If you are in the right folder then you will need to turn it into a git repo by running this command:

git init

Read the official documentation on how to intialize a git repo.

If you are in the right folder AND it is already a git repo then you have probably incorrectly edited the .git file, so you will need to correct that file to resolve the error.

Summary

You can now check which directory you’re in and check if it is already a git repo, both of which are necessary steps in dealing with the “fatal: not a git repository” git error message.