Git error on git pull (unable to update local ref)
GitCommand Line-InterfaceGit Problem Overview
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
Git Solutions
Solution 1 - Git
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 :
Solution 2 - Git
I solved as below:
git remote prune origin
Solution 3 - Git
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 - Git
Try to use this command in your git repository root folder:
rm .git/logs/refs/remotes/origin/master
Solution 5 - Git
rm .git/refs/remotes/origin/master
It works to me!
Solution 6 - Git
Problem
Windows users can often have this problem
git pull
gives the error: error: cannot lock ref
unable to update local ref
Cause
Cause a) There are multiple branches, whose names from the beginning up to any slash (or to the end), differ only in upper and lower case.
Branch name clashing (upper/lower case)
#######################################
# Example 1)
#############################
feature/releasecandidate/fix123
feature/releaseCandidate/improveFeature789
------------------------
^
Identical from beginning up to a slash (here the 2nd one)
except for the marked letter, where the upper/lower case differs
# Example 2)
#############################
releaseBranch
releasebranch
-------------
^
Identical from beginning to the end
except for the marked letter
Cause b) Also a problem on linux: One branch is a prefix of another, with a slash boundary:
Prefix with slash-boundary
#######################################
# Example 1) - also a problem on linux
#############################
feature/release2021
feature/release2021/fixIssue07
^
slash boundary
# Example 2)
#############################
feature/release2022
feature/Release2022/fixIssue99
^ ^
differing case slash boundary
(problem on
windows)
Solution
Remove the cause (see exact Cause above).
# inspect your branches, to see if you have the upper/lower case problem git ls-remote --heads YOUR-GIT-URL
For example: create a branch-naming policy, e.g. all in lower-case letters; or letters before the last slash in lower-case. Or some smart hook, that detect a violation. (but note: In cause a) the problem is only on windows, not on linux).
Background
The problem is that windows stores these branches (from example 1 and 2) in the .git
folder
# inspect the files/folders under .git/refs/remotes/origin/
and in Cause a) windows cannot distinguish the differences in upper/lower case, so git on window goes crazy.
In Cause b) you cannot have a folder (e.g. feature/release2021/
) with the same name as a file (feature/release2021
).
Workaround
A short-term workaround that often works (until you've removed the cause) is:
git pack-refs --all
# delete the contents of .git/refs/remotes/origin/*
rm -rf .git/refs/remotes/origin/*
git pull; git pull; git pull # all good? yes!
Solution 7 - Git
I discoverd the same Error message trying to pull from a Bitbuck Repo into my lokal copy. There is also only one Branche Master and the command git pull origin master
lead to this Error Message
From https://bitbucket.org/xxx
* branch master -> FETCH_HEAD
error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.
Solution as follows
git reflog
find the number of the last commitgit reset --hard <numnber>
reset to the last commitgit pull origin master
pull again without error
Solution 8 - Git
DIRECT ANSWER
git remote prune origin
rm .git/refs/remotes/origin/master
git fetch
git pull origin master
Run the above command step by step
Solution 9 - Git
This was enough for Windows:
> git pack-refs --all
Solution 10 - Git
Ensure the user that is executing the git pull
is the same user that created the repository. The file permissions are incorrect.
Solution 11 - Git
What happened over here?
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.
git remote prune origin
actually cleans this local references and then run git pull
again.
Suggestion - Please run with --dry-run
option for safety
Solution 12 - Git
What worked for me was:
git config --global fetch.prune true
Now it keeps on running prune automatically.
Solution 13 - Git
Clone the repository again, and copy the .git folder in your broken project.
Solution 14 - Git
I've remove the local ref of the branch with:
git branch -d -r REPO/.git/refs/remotes/origin/BRANCHNAME
then I can do my fetch.
Or more radically
rm -rf REPO/.git/refs/remotes/origin
This works everytime too.
Solution 15 - Git
This is probably a very niche situation, but: I run Windows in a Parallels VM on my MacBook Pro, with my local repos stored on the VM's disk, which is shared with macOS.
If I have a file open in a Mac app from a repo that's located on the Windows VM, I sometimes get the "unable to update local ref" error. The solution when this happens is to simply close the file or quit the Mac app.
Solution 16 - Git
This happened to me on OSX where I use a case insensitive file system. Somehow another developer pushed a branch with the same name but different case: My-Branch
vs my-branch
.
I already had My-Branch
checked out and got the error "unable to update local ref" when I did a pull probably because the file system thinks My-Branch
== my-branch
.
Since we use Github I could solve the problem by deleting one of the branches via Github's GUI.
Solution 17 - Git
Remove file .git/logs/refs/remotes/origin/[Locked Branch Name]
Solution 18 - Git
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.
Solution 19 - Git
Speaking from a PC user - Reboot.
Honestly, it worked for me. I've solved two strange git issues I thought were corruptions this way.
Solution 20 - Git
I had the same error, I was updating from within Eclipse and I got many errors. So I tried updating from a DOS command window, and got the same issue.
Then I tried the solution " git gc --prune=now " This gave messages that the files were locked in the refs directory.
Eclipse must have had a locked on something in the "refs" directory.
The solution I found was to simply close Eclipse.
Then I updated the repository from DOS with a " git PULL " command, and everything worked fine.
Solution 21 - Git
I fixed this by deleting the locked branch file. It may seem crude, and I have no idea why it worked, but it fixed my issue (i.e. the same error you are getting)
Deleted:
.git/refs/remotes/origin/[locked branch name]
Then I simply ran
git fetch
and the git file restored itself, fully repaired
Solution 22 - Git
git pull origin <branch_name_you_are_currently_at>
will pull just that branch.
It may or may not give you merge conflicts. Resolve them and commit them.
It worked for me.
Solution 23 - Git
I had the same issue on my debian server as the disk is full. No temp file could be created as no space left on device. After cleaning some files, it worked out fine.
Solution 24 - Git
This work for me
rm .git/logs/refs/remotes/origin/master
Solution 25 - Git
One command solution [for Linux/bash users]
- Changing permission by changing ownership of the file.
sudo chown username -R .git
(replace 'username' with your username)
Use sudo if owner of the file is sudo.
- Deleting the file will also solve the problem.
sudo rm .git/logs/refs/remotes/origin/master
Solution 26 - Git
Open Git Bash as admin cd to folder, Git add . Git commit -m "your message" Git push he will now either use built in credentials or ask for username/pw, If built in credentials or username/pw don't work create a PAT and close the window where they ask for credentials a screen will pop up that asks for a PAT