Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull error "unable to update local ref" how to fix this? [duplicate]

This is the error message :

 error: cannot lock ref 'refs/remotes/origin/master': unable to resolve reference 'refs/remotes/origin/master': reference broken
    From https://bitbucket.org/abc/abc
     ! [new branch]        master     -> origin/master  (unable to update local ref)

when I try to pull then it shows "Complete with errors, see above", I forgot what I did before so it result this error came up after I do pull request. What should I do ?

like image 310
My real name Avatar asked Aug 30 '17 10:08

My real name


People also ask

How to fix git pull error cannot lock refs?

The detailed error was: git pull error: cannot lock refs, cannot lock ref refs is at but expected, how to fix? This will do is remove references to remote branches in the folder .git/refs/remotes/origin.

Why can't I update my Local ref on GitHub?

Since we use Github I could solve the problem by deleting one of the branches via Github's GUI. This error with (unable to update local ref) can also happen if you have changed passwords recently and there's some fancy stuff integrating your Windows and Linux logins.

Why is git pull not working on my Broken project?

The local references to your remote branches were changed and hence when you run git pull, git doesn't find any corresponding remote branches and hence it fails. actually cleans this local references and then run git pull again. Now it keeps on running prune automatically. Clone the repository again, and copy the .git folder in your broken project.

Why can't I update my local repository?

This error with (unable to update local ref) can also happen if you have changed passwords recently and there's some fancy stuff integrating your Windows and Linux logins. Show activity on this post. Clone the repository again, and copy the .git folder in your broken project.


1 Answers

It sounds like your ref to the origin/master branch is broken or corrupt.

First - take a copy of your local repo.

You can do two things (that I know of):

  1. Delete the ref to master and then do a fetch (to get the latest): cd <path-to-your-repo> rm .git/refs/remotes/origin/master git fetch

  2. Try using the git maintenance features:

    • git gc --prune=now
    • git remote prune origin (may not need this which removes stale remote tracking branches and such)

Note: One reason to backup before you do this is that the git gc pruning permanently removes some commits that are un-reachable - which, in theory, you might need incase you made a mistake.

like image 178
code_fodder Avatar answered Sep 23 '22 00:09

code_fodder