Git Error - Unable to resolve reference refs/remotes/origin/master reference broken
When I tried to do a
git pull, I’m getting the following error:
$ git pull error: cannot lock ref 'refs/remotes/origin/master': unable to resolve reference 'refs/remotes/origin/master': reference broken
Accepted Answer - 1
To fix this error, remove the following file
YOURPROJECT/.git/refs/remotes/origin/master, and then run
git fetch to download it again.
Execute the following command within your project’s directory.
rm .git/refs/remotes/origin/master git fetch
git pull and it should work this time.
git pull > Already up to date.
Note: Use the command for any branch that’s giving the error. For example, if I’m getting error for the main branch instead, I could do the following:
rm .git/refs/remotes/origin/main git fetch
Accepted Answer - 2
You can fix this error by cleaning up your local repository.
git gc --prune=now
Additionally, you can also run,
git remote prune origin
Please add or improve the answers above. All contributions are welcome and will help the next person.