git pull fails "unable to resolve reference" "unable to update local ref"

Solution 1:

Try cleaning-up your local repository with:

$ git gc --prune=now
$ git remote prune origin

man git-gc(1):

git-gc - Cleanup unnecessary files and optimize the local repository

git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]

       Runs a number of housekeeping tasks within the current repository, such as compressing file revisions
       (to reduce disk space and increase performance) and removing unreachable objects which may have been
       created from prior invocations of git add.

       Users are encouraged to run this task on a regular basis within each repository to maintain good disk
       space utilization and good operating performance.

man git-remote(1):

git-remote - manage set of tracked repositories

git remote prune [-n | --dry-run] <name>

           Deletes all stale remote-tracking branches under <name>. These stale branches have already been
           removed from the remote repository referenced by <name>, but are still locally available in
           "remotes/<name>".            

Solution 2:

Happened to me as well. In my case, the bad ref was master, and I did the following:

rm .git/refs/remotes/origin/master
git fetch

This made git restore the ref file. After that everything worked as expected again.

Solution 3:

This did the job for me:

git gc --prune=now

Solution 4:

For me, it worked to remove the files that are throwing errors from the folder .git/refs/remotes/origin/.