cannot lock ref 'refs/remotes/origin/master'
Asked Answered
D

13

65

I always got cannot lock ref 'refs/remotes/origin/master' when I execute git 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>
Destructible answered 27/9, 2019 at 0:50 Comment(2)
This sort of error message usually implies some permissions issue with your repository. What those might be on Windows, I'm not sure.Coset
This answer explains some of the underlying Git management for the reverse case, where there's a blocker on the local refs that prevent the remote being created, but some of the explanation may still be relevant: stackoverflow.com/a/76012255Sherwin
G
134

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.

Gibb answered 3/3, 2020 at 14:14 Comment(3)
A permanent solution that finally worked!Laterality
This solution should have a star mark. It worked for me!Scraggy
"git remote prune origin" didn't work for me, but this command did.Sulphurous
P
46

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.

Petrinapetrine answered 10/6, 2020 at 20:50 Comment(2)
Thanks a lot. It worked like a miracle. You are a lifesaver.Coquetry
Life saver my god.Trave
E
19
git remote prune origin

This command worked for me.

Earthshaking answered 20/7, 2021 at 4:26 Comment(0)
A
16

I was able to fix it by just deleting .git/refs/remotes/ and it was restored automatically.

Angeles answered 25/8, 2022 at 12:52 Comment(3)
This answer worked for me. Before this I tried other answers but they didn't work. --> git remote prune origin --> git update-ref -d refs/remotes/origin/releases/branch1Endogenous
Previously "git remote prune origin" worked for me. But somehow recently it stopped working for me. Deleting .git/refs/remotes/ worked for me this time. Thanks.Coquetry
I had a blue screen on the machine running my GitLab runner and tried everything under the sun - this was the only thing that worked.Cumulostratus
V
5

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 has index.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.

Vulcanite answered 27/9, 2019 at 4:55 Comment(2)
Yes, 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 the git pull command later?Destructible
@DonghuaLiu Yes, the remote branches will be back at the next pull, which includes a fetch.Vulcanite
A
3

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.

Anemic answered 10/9, 2021 at 11:15 Comment(1)
The only command that works for meDarill
G
1

In my case, the branch I was dealing with was transient. So I ended up deleting it from the remote.

git push origin --delete <branchName>

Also in my case, I wasn't authorized to delete a remote branch in our repository. So before I could run the above command I needed that permission.

Gorlin answered 26/10, 2021 at 14:44 Comment(0)
A
1

its working for me after delete branch

git push origin --delete <branchName>
Approve answered 25/5, 2022 at 9:13 Comment(0)
D
0

I had this issue and worked out a possible root cause, there were multiple branches with the same name, differing only in case, eg

db/AA-12345-my-branch and db/AA-12345-MY-BRANCH

The answer from Sanjay Gupta - specifically the git update-ref resolved the local issue -

Disagreement answered 8/4, 2022 at 8:48 Comment(0)
P
0

I had this issue and spend a lot of time fixing this. But Nothing worked for me, I just created a new branch from the same branch and pushed the code to the new branch.

Philbin answered 15/4, 2022 at 18:8 Comment(0)
B
0

I had this error but trying to upgrade flutter.

ProcessException: Process exited abnormally: error: cannot lock ref 'refs/remotes/origin/stable': is at 52

If this is your case don't worry, just check that you are in the correct channel (with flutter channel) and try again the flutter upgrade

Baugher answered 9/11, 2022 at 19:42 Comment(0)
H
0

checkout to a new branch

git checkout -b new-branch

Push the current remote branch

git push [origin] new-branch
Heptarchy answered 14/3, 2023 at 9:50 Comment(0)
D
0

FYI The only thing that worked for me was to do:

git cache clean

I tried all of the above and that did not work for my particular issue.

Darter answered 27/9, 2023 at 13:55 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Gingrich

© 2022 - 2024 — McMap. All rights reserved.