"fatal: Not a git repository (or any of the parent directories)" from git status
Asked Answered
M

15

138

This command works to get the files and compile them:

git clone a-valid-git-url

for example:

git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts

However, git status (or any other git command) then gives the above fatal: Not a git repository (or any of the parent directories) error.

What am I doing wrong?

Moraine answered 14/8, 2012 at 22:14 Comment(1)
The checked-out code is in the liggghts directory.Kostroma
S
217

You have to actually cd into the directory first:

$ git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts
Cloning into 'liggghts'...
remote: Counting objects: 3005, done.
remote: Compressing objects: 100% (2141/2141), done.
remote: Total 3005 (delta 1052), reused 2714 (delta 827)
Receiving objects: 100% (3005/3005), 23.80 MiB | 2.22 MiB/s, done.
Resolving deltas: 100% (1052/1052), done.

$ git status
fatal: Not a git repository (or any of the parent directories): .git
$ cd liggghts/
$ git status
# On branch master
nothing to commit (working directory clean)
Sapp answered 14/8, 2012 at 22:19 Comment(2)
You also get this error when git hoses it's own .git directory. I did a pull, and saw the message "Auto packing the repository in background for optimum performance." I then tried to do some more operations, only getting OP's error message. My .git folder is still there, but git has somehow corrupted it. Running git init fixed the problem.Sunflower
How stupid I am. Trying git status before going to the directory :) Thank you so much.Kronstadt
A
35

I just got this message and there is a very simple answer before trying the others. At the parent directory, type git init

This will initialize the directory for git. Then git add and git commit should work.

Aalto answered 10/1, 2017 at 21:40 Comment(3)
Before or after the clone? Would this create a new git repo? How would this work with the existing git repo and history that was cloned? What happens to the original remote setting under this arrangement?Sapp
This is the git equivalent of forgetting a semi-colon, gosh I feel so stupid 😂Partizan
2023 Update: git init will show a message that the current git repository as been 'reinitialized' but will NOT affect files (from the clone) or the remote settings. However it is irelevant as the actual OP issue is still that the user needs to cd into the directory to do thisSapp
A
15

In my case, was an environment variable GIT_DIR, which I added to access faster.

This also broke all my local repos in SourceTree :(

Absorbed answered 2/10, 2015 at 9:15 Comment(2)
export GIT_DIR=path/to/dir/.gitIntercommunicate
omg.. I accidentally introduced a variable with exact same name in my scripts, and got the problemRumery
L
11

Sometimes its because of ssh. So you can use this:

git clone https://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts

instead of:

git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts
Lianne answered 19/12, 2016 at 3:44 Comment(2)
I was getting the error just trying to clone a repo to my local machine. I switched FROM using https:// TO git:// and it was successfully cloned. Thx for pointing me in the right direction.Suppositious
I used git clone [email protected] and it worked for me.Mickelson
L
8

If Existing Project Solution is planned to move on TSF in VS Code:

open Terminal and run following commands:

  1. Initialize git in that folder (root Directory)

    git init

  2. Add Git

    git add .

  3. Link your TSf/Git to that Project - {url} replace with your git address

    git remote add origin {url}

  4. Commit those Changes:

    git commit -m "initial commit"

  5. Push - I pushed code as version1 you can use any name for your branch

    git push origin HEAD:Version1

Lowe answered 17/6, 2020 at 8:46 Comment(0)
G
6

This error got resolved when I tried initialising the git using git init . It worked

Gehlbach answered 26/1, 2019 at 21:51 Comment(0)
I
4

in my case, i had the same problem while i try any git -- commands (eg git status) using windows cmd. so what i do is after installing git for window https://windows.github.com/ in the environmental variables, add the class path of the git on the "PATH" varaiable. usually the git will installed on C:/user/"username"/appdata/local/git/bin add this on the PATH in the environmental variable

and one more thing on the cmd go to your git repository or cd to where your clone are on your window usually they will be stored on the documents under github

cd Document/Github/yourproject

after that you can have any git commands

Imperfection answered 11/8, 2014 at 17:41 Comment(0)
O
4
git clone https://github.com/klevamane/projone.git
Cloning into 'projone'...
remote: Counting objects: 81, done.
remote: Compressing objects: 100% (66/66), done.
remote: Total 81 (delta 13), reused 78 (delta 13), pack-reused 0
Unpacking objects: 100% (81/81), done.

you have to "cd projone"

then you can check status.


One reason why this was difficult to notice at first, i because you created a folder with the same name already in your computer and that was where you cloned the project into, so you have to change directory again


Obstreperous answered 30/8, 2017 at 6:31 Comment(0)
C
3

I had another problem. I was in a git directory, but got there through a symlink. I had to go into the directory directly (i.e. not through the symlink) then it worked fine.

Cosenza answered 14/8, 2014 at 16:56 Comment(0)
B
3

In my case, the original repository was a bare one.

So, I had to type (in windows):

mkdir   dest
cd dest
git init
git remote add origin a\valid\yet\bare\repository
git pull origin master

To check if a repository is a bare one:

git rev-parse --is-bare-repository 
Barefoot answered 9/8, 2017 at 10:34 Comment(0)
O
1

Simply, after you clone the repo you need to cd (change your current directory) to the new cloned folder

git clone https://[email protected]/Repo_Name.git

cd Repo_Name
Operatic answered 10/7, 2017 at 13:16 Comment(0)
T
1

for me; I had been having problems getting the solution to clean properly in Visual Studio, so I did a wildcard delete of any directories called bin, obj... .git has a directory called /objects which was caught up in the delete. I discovered when doing a kdiff of the working clone and the broken one. oops :)

Treenware answered 27/10, 2023 at 14:20 Comment(0)
P
0

I suddenly got an error like in any directory I tried to run any git command from:

fatal: Not a git repository: /Users/me/Desktop/../../.git/modules/some-submodule

For me, turned out I had a hidden file .git on my Desktop with the content:

gitdir: ../../.git/modules/some-module

Removed that file and fixed.

Polygenesis answered 4/10, 2018 at 19:39 Comment(0)
M
0

i have the same problem from my office network. i use this command but its not working for me url, so like this: before $ git clone https://gitlab.com/omsharma/Resume.git

After i Use this URL : $ git clone https://[email protected]/omsharma/Resume.git try It.

Morville answered 19/4, 2019 at 5:49 Comment(0)
T
0

In my case I was dealing with github workflow jobs and simply forgot to checkout the repo before my step. Adding pre requisite step actions/checkout@v2 resolved the issue.

Thionate answered 12/12, 2022 at 6:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.