Fixing Git “error: bad index file sha1 signature”

I was setting up Git on a server at work and came across an issue whereby everything seemed to be setup ok but once I ran git status it would return the following error

error: bad index file sha1 signature
fatal: index file corrupt
fatal: 'git status --porcelain' failed

To the interwebs!

Stackoverflow (how great is Stackoverflow?) implied that the fix was to run the following

rm -f .git/index
git reset

Greeeeeeat! Except it didn’t work…

Having uninstalled git-core I ran this line to search for leftovers

find /webdirectory -name ".git*"

This returned a lot more than it should of. Then the problem hit me- This is a production server with more symlinks than any one admin can keep track of. Basically there were .git directories nested within .git directories.

I ran the following to remove all traces and reinstall

apt-get autoremove git-core

find /webdirectory -name ".git*" -exec rm -rf {} ;

apt-get install git-core

cd /webdirectory/webprojectroot

git init

Job done!

Leave a Reply

Your email address will not be published. Required fields are marked *