Git these days is the most popularly used tool to manage your projects remotely while availing the benefits of version controlling. Sometimes while working with a particular git repository your operations just do not succeed and you face the fatal: not a git repository (or any of the parent directories):.git.
The error can be simply dealt if you follow the right steps to work with Git. In this article, we will go through the solutions that can help you in solving this “not a git repository” error.
Table of Contents
What Causes the fatal: not a git repository Error?
Following are the possible reasons that can cause the error to be raised:
1. You tried to run the Git commands outside of a Git directory/ non-Git folder.
2. The repository in which you re trying to run the command has not been initialized in your project directory.
Solutions to Resolve fatal: not a git repository Error.
Solution#01: Initialize the Git Repository in your Project Folder.
If you are in your project folder, first check if this directory is initialized with git. Use the command ls -la to check this. If you are in git initialized folder you will see the .git/ folder in the output of the project.
If your project folder is not initialized as a git repository, you will not see the .git/ folder in it, like the output given below:

If this is the case, then first initialize the folder by using git init command in the project directory.

After running the git init command, you will now see .git/ folder in the project directory. Let’s check.

Solution#02: View and Open the Right Directory to Perform Git Operations.
To run Git commands successfully you need to be in the right project directory. Following are the steps to navigate to the right directory, make sure you follow them:
1. Open the Command Prompt and go to the right folder where you want to clone the repository, using the cd command.

2. Go to your existing Github repository that you want to connect with local project.
3. Copy the link to clone the repository.

4. Take this copied link and clone the repo with the git clone url. The output will somehow be like the following.

Now you are in the correct folder where your remote repository is cloned, and the git commands should be operational here if it is initialized correctly.
Conclusion
In this article we discussed about the possible causes that can give a rise to the fatal: not a git repository error. Later, we observed the possible solutions to deal with the error. It is indeed possible that if you are following the Git workflow properly you will not get a hit with such errors, but otherwise you can follow this guide to resolve the issue if it occurs.
Suggested Read: Top 50 Git Interview Questions