Unable to Update Local Ref on Git Pull: 4 Ways to Fix it

Optimize the directory and check for bad reference

by Kazim Ali Alvi
Kazim Ali Alvi
Kazim Ali Alvi
Author
Kazim has always been fond of technology, be it scrolling through the settings on his iPhone, Android device, or Windows PC. He's specialized in hardware devices, always ready... read more
Affiliate Disclosure
  • To fix the unable to update local ref error, run the git prune command or delete the corrupt or broken reference. 
  • Keep reading to find out the step-by-step solutions to fix things in no time!
fix unable to update local ref

Many users reported getting the unable to update local ref error when executing the Git Pull or Git Push command. This usually happens due to a mismatch in the commit IDs or due to permission issues when the local repository is created as a different user.

How do I fix the unable to update local ref error?

Before we start with the slightly complex solutions, perform these quick checks:

  • Restart the computer to fix minor corruptions and check for improvements.
  • Make sure you are the owner or have the permission to access the project files.
  • Ensure your git is updated.
  • Inspect the branches and look for any upper/lower case mismatch. Also, verify whether other branches exist with the same. If yes, rename the non-critical ones.

1. Optimize the local directory

A quick solution is to run the following two commands: $ git gc --prune=now $ git remote prune origin

The first command cleans up the unnecessary files. It’s recommended to run it in each repository for optimal disk usage and better performance. The second, remote prune, command removes the old, unused remote-tracking branches.

Remember, you may have to run the second command more than once to fix the unable to update local ref error.

2. Update the reference

If it’s a referencing issue, use this command: $ git update-ref -d refs/remotes/origin/[branch name]

Here, [branch name] refers to the branch that’s throwing the error due to a Commit ID mismatch. Once done, you can continue with the Git Pull or Git Push command.

3. Check for a bad reference

If the bad reference was the master, use this command to make git restore the ref files: rm .git/refs/remotes/origin/master

4. Delete the corrupt or broken references after a BSOD

A BSOD can corrupt stored references, especially the ones that were open or being written to, and subsequently overwrite them with Null characters. To fix that, delete this reference: refs/remotes/origin/some/branch

It’s stored in the following file: %repo_root%/.git/refs/remotes/origin/some/branch

One of these solutions should help fix the unable to update local ref Git error. Remember, there are several underlying causes, but in most cases, the git prune command should do the trick! It works for 7 out of 10 users.

A similar set of fixes works with the Not possible to fast-forward, aborting error.

For any queries or to share what worked for you, drop a comment below.

This article covers:Topics: