Fatal: Not a git repository (or any of the parent directories).git

Git abbreviation of Global Information Tracker is a version control software that manages your files and tracks the commit in these files.   If you are new to use git to manage your Git repositories, you …

fatal not a git repository

Git abbreviation of Global Information Tracker is a version control software that manages your files and tracks the commit in these files.  

If you are new to use git to manage your Git repositories, you may encounter issues running commands in the Git Bash. Here is the solution to one of the common errors Fatal: not a git repository (or any of the parent directories) .git.  This fatal error is easy to resolve within few steps.

What are the reasons behind the getting error Fatal: not a git repository?

There are mainly two reasons behind the issue Fatal: not a git repository.

1. Run git command at wrong path: run git command and not switch to your git repository.

2. You are at the git repository folder, but Git is not initialized.

Problem 1:Run git command at wrong path: run git command without switching to your git folder.

Suppose you want to remove a file and write the remove command in Git Bash, but you are outside the git folder; the system does not know how to perform specific command operations. We get error fatal: not a git repository. The error shows “not a git repository”  because you are working in a folder that is not a git repository.

fatal not a git repository

Solution:

There are two ways to open git repository as your current directory.

  1. Open the right directory by using the git Bash command line.
  2. Go to the Git repository folder and then open the command prompt to run the git commands
  1. Open the right directory by using the git Bash command line.

Write the cd command and path of your git repository folder. It will change your current working directory by opening the Git Repository folder. 

fatal not a git repository

2. Go to the Git repository folder, click on the drop-down arrow.

fatal not a git repository

Replace your git project folder with cmd and press enter.

fatal not a git repository

 It will open the directory of your git repository folder into the command prompt.

fatal not a git repository

Problem 2:  Git repository is not initialized.

Navigate to git repository folder but prompting command still showing the error Fatal: not a git repository. It is because your .git file is hidden, or it may not be initialized. 

You run a git command inside the git directory but still show fatal: not a git repository issue.

fatal not a git repository

Solution:

Check your list of all directories by using the ls -la command. There is no .git folder.

fatal not a git repository

Initialized your repository by git init command.

fatal not a git repository

It will add the .git folder inside the current directory. You can check the directory list.

fatal not a git repository

Now the environment is set to run git commands into your command line. Now you can perform clone, move, remove, and other commands.

Your .git\HEAD file is missing or corrupted can also create fatal: not a git repository issue.

You can get the same fatal error when your HEAD file is missing or corrupted in the .git folder. To solve the issue, initialize git again using the git init command to overcome this fatal issue.

Conclusion

Many of us face the issue fatal: not a git repository when try to access and edit git repository to our local system. It is caused when we run git commands in command prompt without opening git directory, or our git repository is not initialized. In this article, we resolve this issue within simple steps.

Suggested Read: Remove Brackets from list Python

Categories Git

Leave a Comment