Git error on git pull (unable to update local ref)


I only have a master branch and I'm getting this error every time I try to git pull:

error: Couldn't set refs/remotes/origin/master
From /var/lib/git/xxx/project
 ! a0f80ea..49177a3  master     -> origin/master  (unable to update local ref)

And when I run git pull origin master I get:

error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.

I have been searching but can't find why.


My team and I ran into this error, unable to update local ref, when doing a pull in SourceTree.

Update 2020: Per @Edward Yang's answer below, @bryan's comment on this answer, and this question/answer you may need to run both git gc --prune=now and git remote prune origin. Running only the former has always worked for me but based on ppl's responses I think both are necessary to address different causes of the error.

We used:

git gc --prune=now

This removes any duplicate reference objects which should fix the issue.

Here are a few links where you can learn more about git references and pruning :

git tip of the week

git-prune documentation

git references

What is the difference between pull and clone in git?

Git, rewrite previous commit usernames and emails