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

If you try to run a git command to add a file to stage area or commit your current state files into your local branch on the terminal and you get the fatal error "not a git repository",

  • The most likely reason is that you are not in a git directory, do a pwd and confirm.
  • If this is supposed to be a new repository, then go a git init to initialize the directory as a git repo.
  • Check if the directory has a .git folder in it (ls -la).
  • If this directory you are in is supposed to be a new git project then run git init
Git fatal - not a git repository

As you may see in the above screenshot when I did a git add, I got the fatal error saying the current directory is not a git repository, when I did a ls -la, there is not .git folder, and for me, it was supposed to be a new git repo, so I did git init and then tried the git add command and it worked like a charm.

Happy coding!

Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.