Fixing a git repo

If git complains with this error:

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

This may happen if upstream branches have been removed and your origin is pointing to it. You can confirm this by running:

cat .git/refs/remotes/origin/HEAD

If it is pointing to a branch that doesn't exist,

Running git remote set-head origin --auto
followed by git gc
will fix it

Chris Almost 6 years ago