[git] git status shows fatal: bad object HEAD

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 git fsck shows:

broken link from  commit 739df633f185ce5d1ab7eb97d619b28e7d81185a
              to    tree 2a6d4876d135c1fa7cbe1348c62570006e895fc5
broken link from  commit 9c7eae5ffed34dbfac977e515dee675626b59f93
              to    tree 400132d215ab9aced883a9971e648b82624b2032
broken link from  commit 9c7eae5ffed34dbfac977e515dee675626b59f93
              to  commit 4a49af0a0cb64a0a0415734b11772d6df18561fb
broken link from  commit bc3072f30e71c616a8196089e19a67a2c9c0a5ad
              to    tree 0aa813c183487d0a1b1f7ae81501ca7a1168283f
broken link from  commit d3bb4f8545e91ec8ace15ad31a3147d92a1d4242
              to    tree 4682108accd8e72fe68858232386dffe60f9f02d
broken link from  commit 6b34795c4b54286301bcdc0ed254a04c132cb2ad
              to    tree 5c57dd3222d11924dba841d3cae517bdc9220601
broken link from  commit d70172d855391b93bc1c5eeb9b4226df525dfc6e
              to  commit 390c8cbd527c8e707c51e25142e54421f4dd3948
broken link from  commit cc05e8d2e3733693ebb67d697ae4b65e51fea79a
              to  commit 32f081f8b901425fd1e8898478f0551970bee0f5
broken link from    tree 6a75ed6d0311d800078e77f43d427d128372d5bc
              to    blob 4a064d610c0e7207967d59934c8bc5f491f26dae
broken link from    tree 6a75ed6d0311d800078e77f43d427d128372d5bc
              to    tree 5c06ec964dcbade49287d0f36efe1f7b60f446e3
broken link from    tree b4855fa6734b5652a93a9b799eafe47fad0d13a0
              to    blob 3e1fb421613dc9066cbf9c95eddc61619a9f8eed
broken link from    tree b4855fa6734b5652a93a9b799eafe47fad0d13a0
              to    tree 556a50048d42346c283c94b78ea278ba1d57d251
broken link from    tree 289c03409370c4ca7c12266ce2822a2976bd032b
              to    blob 3abf3c48ada45f63404dcf4d675ddfdadcfa83c6
broken link from    tree 289c03409370c4ca7c12266ce2822a2976bd032b
              to    blob 3fa569892003b468ed1301426dd6d96d9644be3c
broken link from    tree 289c03409370c4ca7c12266ce2822a2976bd032b
              to    blob 0a9a54a51e84f3bc34122dbce1146d895fcbe22c
broken link from    tree 289c03409370c4ca7c12266ce2822a2976bd032b
              to    blob 3fa48873564361b4d95830803ae77f79eeafaf5b

git branch shows - *master

This question is related to git github

The answer is


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

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.


This happened to me on a old simple project without branches. I made a lot of changes and when I was done, I couldn't commit. Nothing above worked so I ended up with:

  1. Copied all the code with my latest changes to a Backup-folder.
  2. Git clone to download the latest working code along with the working .git folder.
  3. Copied my code with latest changes from the backup and replaced the cloned code (not the .git folder).
  4. git add and commit works again and I have all my recent changes.

Running

git remote set-head origin --auto

followed by

git gc

I had a similar problem and what worked for me was to make a new clone from my original repository


Your repository is broken. But you can probably fix it AND keep your edits:

  1. Back up first: cp your_repository your_repositry_bak
  2. Clone the broken repository (still works): git clone your_repository your_repository_clone
  3. Replace the broken .git folder with the one from the clone: rm -rf your_repository/.git && cp your_repository_clone/.git your_repository/ -r
  4. Delete clone & backup (if everything is fine): rm -r your_repository_*

In my case the error came out of nowhere, but didn't let me push to the remote branch.

git fetch origin

And that solved it.

I agree this may not solve the issue for everyone, but before trying a more complex approach give it a shot at this one, nothing to loose.


I solved this by copying the branch data (with the errors) to my apple laptop local git folder.

Somehow in the terminal and when running: git status, tells me more specific data where the error occurs. If you look under the errors, hopefully you see a list of folders with error. In my case GIT showed the folder which was responsible for the error. Deleting that folder and commiting the branche, I succeeded. git status was working again the other devices updating by git pull; everything working again on every machine.

Hopefully this will work for you also.


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.


I solved this by renaming the branch in the file .git/refs/remotes/origin/HEAD.


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.


try this : worked for me rm -rf .git

You can use mv instead of rm if you don't want to loose 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


Make a copy of your git dir in your local host and run git init there once again. Push the project to a brand new reprository.