fatal: bad object refs/remotes/origin/HEAD

After running git gc the following error occurs:

Possible wrong branch in:

.git/refs/remotes/origin/HEAD

Example:

ref: refs/remotes/origin/acceptance

You can automaticly restore the branch with:

git remote set-head origin --auto

Output:

origin/HEAD set to test-alpha