$show=/label

[Fixed] fatal: not a git repository (or any of the parent directories): .git in 2 ways

SHARE:

A quick guide to fix git error fatal: not a git repository (or any of the parent directories): .git on windows, mac and heroku with simple steps.

 

1. Overview

In this tutorial, We'll learn how to fix git error "fatal: not a git repository (or any of the parent directories): .git" on windows or mac os or Heroku.

Fixing this error can be done in 2 ways. But first, let us understand the error what is the meaning of the error.


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



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


This fatal error "not a git repository" is produced when you are running any git command on a non-git project location.

For example, run the git status command to see the current status of the git stage.

In the below example, I have created a new folder and executed the git status command.

MacBook-Pro-2:workspace $  git status
fatal: not a git repository (or any of the parent directories): .git
MacBook-Pro-2:workspace $ 

You can see the what is the reason for this error.

Not only git status command but also try with any commands like below. All will produce the same error "fatal: not a git repository (or any of the parent directories): .git" except "git init" and "git clone" commands.

$ git add *.java
fatal: not a git repository (or any of the parent directories): .git
$ 
$ git push
fatal: not a git repository (or any of the parent directories): .git
$ 
$ git commit -m 'git changes'
fatal: not a git repository (or any of the parent directories): .git
$ 
$ git remote -v
fatal: not a git repository (or any of the parent directories): .git
$ 
$ git branch
fatal: not a git repository (or any of the parent directories): .git
$ 


3. Fix 1 - fatal: not a git repository (or any of the parent directories): .git


This is the simple fix but you must have cloned the git repo already. 

Then check the current location using pwd command and then run the ls -la command.

$ ls -larth
total 0
drwxr-xr-x  27 venkateshn  staff   864B Nov 29 19:19 ..
drwxr-xr-x   3 venkateshn  staff    96B Nov 29 19:22 .
drwxr-xr-x  6 javaprogramto  staff   192B Nov 29 19:22 Kotlin-Demo
$ pwd
/Users/javaprogramto/workspace/dummy
$

From the above ls -larth command, we did not find any files related to the git like .git folder. That means this is not a git repositoiry. Becuase of thsi reason we are getting fatal not a git repository.

To fix now, we need to navigate to the right folder where we have cloned the git project.

ls command shown one folder Kotlin-demo. Let us run the unix ls command inside this folder and look for the git folders if any.

$ cd Kotlin-Demo/
$ 
$ ls -larth
total 8
drwxr-xr-x   3 venkateshn  staff    96B Nov 29 19:22 ..
-rw-r--r--   1 venkateshn  staff   498B Nov 29 19:22 Kotlin-Demo.iml
drwxr-xr-x   3 venkateshn  staff    96B Nov 29 19:22 out
drwxr-xr-x   6 venkateshn  staff   192B Nov 29 19:22 .
drwxr-xr-x   3 venkateshn  staff    96B Nov 29 19:22 src
drwxr-xr-x  13 venkateshn  staff   416B Nov 29 19:22 .git
$ 

Now, there is a one hidden folder with name ".git". This is indicagting that current folder is managed by git. So, if you run any git commands should not be thrown "is not a git repository" error now.

Let us see now, what would be output.

$ git branch
* master
$
$ git remote -v
origin	https://github.com/JavaProgramTo/Kotlin-Demo.git (fetch)
origin	https://github.com/JavaProgramTo/Kotlin-Demo.git (push)
$

Great. It works well without any errors.


4. Fix 2 - fatal: not a git repository (or any of the parent directories): .git


In the previous section, we assumed this error encounterd after clonng the reposotory.

But now we did not clone any git repo. 

In this case, we want to turn the current folder into git project but when we run git status command to see the files which are modified, we get the error fatal: not a git repository.

To fix in this case now, we need to initialize the current project into git using git init command.

$ mkdir newrepo
$ ls -l
total 0
drwxr-xr-x  6 venkateshn  staff  192 Nov 29 19:22 Kotlin-Demo
drwxr-xr-x  2 venkateshn  staff   64 Nov 29 19:31 newrepo
$ 
$ cd newrepo/
$ 
$ touch firstfile>txt
$ ls -l
total 0
-rw-r--r--  1 venkateshn  staff  0 Nov 29 19:31 firstfile>txt
$ git status
fatal: not a git repository (or any of the parent directories): >git
$ 
$ git init
Initialized empty Git repository in /Users/venkateshn/Documents/VenkY/blog/workspace/dummy/newrepo/>git/
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>>>>" to include in what will be committed)

	firstfile>txt

nothing added to commit but untracked files present (use "git add" to track)
$ 


In the above commands,. first created a new folder with newrepo and went inside to run the command git status. But it thrown the error. Next, ran git init command. After that no issue with the git commands.

See the folder structure after git init. It has created the new hidden git folder with name ".git".

$ ls -lrtha
total 0
drwxr-xr-x   4 venkateshn  staff   128B Nov 29 19:31 ..
-rw-r--r--   1 venkateshn  staff     0B Nov 29 19:31 firstfile.txt
drwxr-xr-x   4 venkateshn  staff   128B Nov 29 19:31 .
drwxr-xr-x  10 venkateshn  staff   320B Nov 29 19:31 .git


5. Conclusion


In this article, We've seen how to fix git error fatal: not a git repository (or any of the parent directories): .git in 2 ways.

Summary fix in 2 ways

5.1 Navigate to the correct git project location
5.2 If the current project is not a git project, please run git init command to make the project as git project.


COMMENTS

BLOGGER

About Us

Author: Venkatesh - I love to learn and share the technical stuff.
Name

accumulo,1,ActiveMQ,2,Adsense,1,API,37,ArrayList,18,Arrays,24,Bean Creation,3,Bean Scopes,1,BiConsumer,1,Blogger Tips,1,Books,1,C Programming,1,Collection,8,Collections,37,Collector,1,Command Line,1,Comparator,1,Compile Errors,1,Configurations,7,Constants,1,Control Statements,8,Conversions,6,Core Java,149,Corona India,1,Create,2,CSS,1,Date,3,Date Time API,38,Dictionary,1,Difference,2,Download,1,Eclipse,3,Efficiently,1,Error,1,Errors,1,Exceptions,8,Fast,1,Files,17,Float,1,Font,1,Form,1,Freshers,1,Function,3,Functional Interface,2,Garbage Collector,1,Generics,4,Git,9,Grant,1,Grep,1,HashMap,2,HomeBrew,2,HTML,2,HttpClient,2,Immutable,1,Installation,1,Interview Questions,6,Iterate,2,Jackson API,3,Java,32,Java 10,1,Java 11,6,Java 12,5,Java 13,2,Java 14,2,Java 8,128,Java 8 Difference,2,Java 8 Stream Conversions,4,java 8 Stream Examples,12,Java 9,1,Java Conversions,14,Java Design Patterns,1,Java Files,1,Java Program,3,Java Programs,114,Java Spark,1,java.lang,4,java.util. function,1,JavaScript,1,jQuery,1,Kotlin,11,Kotlin Conversions,6,Kotlin Programs,10,Lambda,2,lang,29,Leap Year,1,live updates,1,LocalDate,1,Logging,1,Mac OS,3,Math,1,Matrix,6,Maven,1,Method References,1,Mockito,1,MongoDB,3,New Features,1,Operations,1,Optional,6,Oracle,5,Oracle 18C,1,Partition,1,Patterns,1,Programs,1,Property,1,Python,2,Quarkus,1,Read,1,Real Time,1,Recursion,2,Remove,2,Rest API,1,Schedules,1,Serialization,1,Servlet,2,Sort,1,Sorting Techniques,8,Spring,2,Spring Boot,23,Spring Email,1,Spring MVC,1,Streams,31,String,61,String Programs,28,String Revese,1,StringBuilder,1,Swing,1,System,1,Tags,1,Threads,11,Tomcat,1,Tomcat 8,1,Troubleshoot,26,Unix,3,Updates,3,util,5,While Loop,1,
ltr
item
JavaProgramTo.com: [Fixed] fatal: not a git repository (or any of the parent directories): .git in 2 ways
[Fixed] fatal: not a git repository (or any of the parent directories): .git in 2 ways
A quick guide to fix git error fatal: not a git repository (or any of the parent directories): .git on windows, mac and heroku with simple steps.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJARyDPXVKWqgaBc_2Y3ULrP_E854K_LXwXWJseXZggo68I4tA6Pl0m_-PLF_ce47KwwPnEQ1GBaPs3DEhjNf8QDYiup9A54MoVc2EUNog2eguwYGhrO6RsZZceAuOJnYBOAJtd6OrlYg/w640-h404/fatal+not+a+git+repository+%2528or+any+of+the+parent+directories%2529+.git+.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJARyDPXVKWqgaBc_2Y3ULrP_E854K_LXwXWJseXZggo68I4tA6Pl0m_-PLF_ce47KwwPnEQ1GBaPs3DEhjNf8QDYiup9A54MoVc2EUNog2eguwYGhrO6RsZZceAuOJnYBOAJtd6OrlYg/s72-w640-c-h404/fatal+not+a+git+repository+%2528or+any+of+the+parent+directories%2529+.git+.png
JavaProgramTo.com
https://www.javaprogramto.com/2021/11/fatal-not-a-git-repository.html
https://www.javaprogramto.com/
https://www.javaprogramto.com/
https://www.javaprogramto.com/2021/11/fatal-not-a-git-repository.html
true
3124782013468838591
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content