How to handle git gc fatal: bad object refs/remotes/origin/HEAD error?

Ryan picture Ryan · May 10, 2016 · Viewed 48.8k times · Source

I randomly hit this today while trying to run Git garbage collect:

$ git gc
fatal: bad object refs/remotes/origin/HEAD
error: failed to run repack

How do I deal with this?

Answer

petrelharp picture petrelharp · Jul 5, 2016

I don't understand the ramifications of this, but as suggested in this thread, when I encountered this I just did

$ mv .git/refs/remotes/origin/HEAD /tmp

(keeping it around just in case) and then

$ git gc

worked without complaining; I haven't run into any problems.