git status shows fatal: bad object HEAD
Solution 1:
try this; it worked for me (Warning: this destroys work that exists only in your local repo):
rm -rf .git
You can use mv
instead of rm
if you don't want to lose your stashed commits
then copy .git from other clone
cp <pathofotherrepository>/.git . -r
then do
git init
this should solve your problem , ALL THE BEST
Solution 2:
Your repository is corrupt. That means data is lost that cannot be recovered by git itself. If you have another clone of this repository, you can recover the objects from there, or make a new clone.
fatal: bad object HEAD
means the branch referenced from HEAD is pointing to a bad commit object, which can mean it's missing or corrupt.
From the output of git fsck
, you can see there are a few tree, blob and commit objects missing.
Note that using git itself is not enough to keep data safe. You still need to back it up in cases of corruption.
Solution 3:
This happened because by mistake I removed some core file of GIT. Try this its worked for me.
re-initialize git
git init
fetch data from remote
git fetch
Now check all your changes and git status by
git status