cannot lock ref 'refs/remotes/origin/master'
Solution 1
You need to update the reference using following Git command on Git bash:
$ 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 2
My error looked a little different:
error: cannot lock ref 'refs/remotes/origin/releases/branch1': 'refs/remotes/origin/ releases' exists; cannot create 'refs/remotes/origin/releases/branch1'
! [new branch] releases/branch1 -> origin/releases/branch1 (failed to update the local link).
The error disappeared after executing the command:
git remote prune origin
By the way, TortoiseGit advised her to do it. But this
git update-ref -d refs/remotes/origin/releases/branch1
command did not help.
Solution 3
git remote prune origin
This command worked for me.
Solution 4
If you have a VSCode running, you might want to close it first.
As seen in "microsoft/vscode
issue 47141"
This issue occurs when git-radar is doing a fetch in background and user runs git fetch/pull.
Git hasindex.lock
to lock index during a fetch, so you cannot corrupt the index by doing concurrent fetches.
Your git command fails because of this lock prevents git modifying index.
You can also try git remote prune origin
as mentioned here.
Solution 5
git remote prune origin
it worked fine for me. I think that what the command is doing is comparing the list of branches between your local and remote repositories and remove the one that doen't exist anymore in the remote repository from the local one.

Donghua Liu
Updated on October 27, 2021Comments
-
Donghua Liu about 1 year
I always got
cannot lock ref 'refs/remotes/origin/master'
when I executegit pull
first time if there are some updates.The full console log is belows.
D:\code\react-native\expo-multi-screen-starter>git pull error: cannot lock ref 'refs/remotes/origin/master': is at b2459b4d5af42622cba55f9fe47ccd14fbd879bc but expected 76f11048c866cfe3e6570eaacf90db3cb7732723 From github.com:liudonghua123/expo-multi-screen-starter ! 76f1104..b2459b4 master -> origin/master (unable to update local ref) D:\code\react-native\expo-multi-screen-starter>git pull App.js | 19 ++++----- src/navigation/AuthStack.js | 14 +++++++ src/navigation/RootNavigator.js | 22 ++++++++++ src/navigation/TabNavigator.js | 4 +- src/screens/AuthLoadingScreen.js | 35 ++++++++++++++++ src/screens/HomeScreen.js | 19 +++++++++ src/screens/{LoginScreen.js => SignInScreen.js} | 54 ++++++++++++++++++++++--- 7 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 src/navigation/AuthStack.js create mode 100644 src/navigation/RootNavigator.js create mode 100644 src/screens/AuthLoadingScreen.js rename src/screens/{LoginScreen.js => SignInScreen.js} (61%) D:\code\react-native\expo-multi-screen-starter>
-
Donghua Liu about 3 yearsYes, I run
git pull
in the integrated terminal in VSCode often.git remote prune origin
seems to remove references to remote branches in the folder.git/refs/remotes/origin
, Is it safe operation, no influence to thegit pull
command later? -
VonC about 3 years@DonghuaLiu Yes, the remote branches will be back at the next pull, which includes a fetch.
-
Alok Ranjan about 2 yearsThanks a lot. It worked like a miracle. You are a lifesaver.
-
jh95 almost 2 yearsA permanent solution that finally worked!
-
Daisy over 1 yearLife saver my god.
-
Kashyap Neeraj about 1 yearThis solution should have a star mark. It worked for me!
-
Đỗ Tiến 7 monthsThe only command that works for me