I have a problem with git on Windows Azure. Git status shows - \"fatal: bad object HEAD\" and I tried running:
git fsck --full
git gc
But
I managed to fix a similar problem to this when some of git's files were corrupted:
https://stackoverflow.com/a/30871926/1737957
In my answer on that question, look for the part where I had the same error message as here:
fatal: bad object HEAD.
You could try following what I did from that point on. Make sure to back up the whole folder first.
Of course, your repository might be corrupted in a completely different way, and what I did won't solve your problem. But it might give you some ideas! Git internals seem like magic, but it's really just a bunch of files which can be edited, moved, deleted the same as any others. Once you have a good idea of what they do and how they fit together you have a good chance of success.
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
I solved this by doing git fetch. My error was because I moved my file from my main storage to my secondary storage on windows 10.
This is unlikely to be the source of your problem - but if you happen to be working in .NET you'll end up with a bunch of obj/
folders. Sometimes it is helpful to delete all of these obj/
folders in order to resolve a pesky build issue.
I received the same fatal: bad object HEAD
on my current branch (master) and was unable to run git status
or to checkout any other branch (I always got an error refs/remote/[branch] does not point to a valid object
).
If you want to delete all of your obj
folders, don't get lazy and allow .git/objects
into the mix. That folder is where all of the actual contents of your git commits go.
After being close to giving up I decided to look at which files were in my recycle bin, and there it was. Restored the file and my local repository was like new.
Your repository is broken. But you can probably fix it AND keep your edits:
cp your_repository your_repositry_bak
git clone your_repository your_repository_clone
rm -rf your_repository/.git && cp your_repository_clone/.git your_repository/ -r
rm -r your_repository_*
I solved this by renaming the branch in the file .git/refs/remotes/origin/HEAD
.