Git error on git pull (unable to update local ref)
I only have branch master and im 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 do "git pull origin master" i get:
error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.
i have been searching but cant find why
Solution 1:
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
andgit 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
Solution 2:
I solved as below:
git remote prune origin
Solution 3:
with gitbach line commande, use git update-ref
to update reference of your local branch:
$ git update-ref -d refs/remotes/origin/[locked branch name]
then pull using $ git pull
[locked branch name]
is the name of the branch that the error is happening because of mismatch of commit Ids.
Solution 4:
Try to use this command in your git repository root folder:
rm .git/logs/refs/remotes/origin/master