I had the same error message when opening the repository in "GitX" (GUI tool).
For me, the problem was caused by the .git/refs/remotes/origin/HEAD
file, which referred to a remote branch that I deleted:
ref: refs/remotes/origin/develop
I fixed it by editing the file to contain the name of the name of the remote branch that still exists:
ref: refs/remotes/origin/master
source share