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
If you're using git worktrees, make sure you're doing a
git worktree prune
before running
git gc
I had a worktree get corrupted and this seemed to do the trick after removing the corrupted worktree. git prune by itself didn't seem to work.
git prune