10

I have a remote folder that I am currently unable to push to. When I go directly to the remote directory and a do a 'git status' it reads:

fatal: Not a git repository

The .git folder does exists and it was working fine yesterday and nothing has changed since.

Can anyone tell me the reason(s) why I might receive this message even though the .git folder exists?

Thanks in advance for your help. Much appreciated!

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
BIOSTALL
  • 1,656
  • 12
  • 25
  • 2
    missing rights on the .git directory ? – Rufinus Dec 08 '11 at 16:47
  • If not what @Rufinus suggests quite appropriately, possibly file system corruption... – Romain Dec 08 '11 at 16:49
  • what is the msg you get when to try to push? – havexz Dec 08 '11 at 16:49
  • Thanks for your response. I've compared the permissions to another .git repository on the same server and they match exactly – BIOSTALL Dec 08 '11 at 16:49
  • The error I get when pusshing is as follows: fatal: '/var/www/vhosts/X.co.uk/httpdocs': unable to chdir or not a git archive Pushing to root@X.co.uk:/var/www/vhosts/X.co.uk/httpdocs fatal: The remote end hung up unexpectedly – BIOSTALL Dec 08 '11 at 16:50
  • also can you run `git --config -l` and put the lines related to remote? – havexz Dec 08 '11 at 17:51

2 Answers2

9

If the permissions on the .git folder are fine, see that there is a file .git/HEAD existing or is not named wrongly like .git/head. The presence of .git/HEAD ( or HEAD in case of bare) is the secondary check for a git repository

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 3
    If `.git/HEAD` exists and you still get this error, ensure that the *content* of `.git/HEAD` points to a valid reference. If git cannot parse the content, it also outputs that the repository is invalid. – koppor Aug 27 '13 at 11:41
  • 2
    what is .git/HEAD does not exist? (in my case only .git/ORIG_HEAD exists) and I'm having the same problem as the OP. – Sean Ahrens Sep 08 '14 at 10:14
  • @SeanAhrens I had a corrupted `HEAD` file, and a fine `ORIG_HEAD` file. Copying the latter over the former fixed my issue and got me back into a correct state. You could run `git reflog` to see recent HEAD positions once that's done, in case you need to reset to a different commit. – Drew Noakes Mar 10 '18 at 19:04
  • Probably a good idea to run `git fsck --full` after such a manual recovery, just to check if there's any corruption. – Drew Noakes Mar 10 '18 at 19:07
1

Clone the remote repository into another folder and compare the .git folders. This will give you indication about missing or corrupted files. You'll probably see a difference in the objects folder that you can ignore.

yorammi
  • 6,272
  • 1
  • 28
  • 34
  • With such a test, differences in the `objects` folder are not necessarily a problem. – Drew Noakes Mar 10 '18 at 19:05
  • Correct, but in the other folders and files it may indicate what is the problem – yorammi Mar 11 '18 at 06:51
  • @DrewNoakes, I've updated my answer for your comment. Thanks! – yorammi Mar 11 '18 at 08:20
  • The content of several files may differ based upon what branch/commit was checked out, how many remotes there are, and what activity has been performed on the repo. `HEAD`, `ORIG_HEAD`, `packed-refs`, `config`, `COMMIT_EDITMSG`... these can all be different and not a sign of problems. I upvoted your answer because it's interesting, but I'm not sure what actionable information such a diff could give to someone looking to solve corruption. I came here when my repo was corrupted, and the tip around checking the `HEAD` file contains a valid SHA-1 was enough for me to fix my problem, thankfully. – Drew Noakes Mar 11 '18 at 20:46