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
When all other answers fail, just restart your computer.
I encountered OP's error and also had Permission denied on some .gitattribute file in unrelated directory (no matter if run by admin or not). This helped me.
Permission denied
.gitattribute