How to resolve: git push remote: error: cannot lock ref .... /refs/head/develop.lock exists
Asked by Joe Dahl-Fisher:

I'm struggling to solve an issues with one of my repositories. It started with a failed push from sourcetree, on attempting to push it again, or to run it in the shell, I am given this error:

emote: error: cannot lock ref 'refs/heads/develop': Unable to create '..../refs/heads/develop.lock': File exists.  
remote:  
remote: Another git process seems to be running in this repository, e.g.  
remote: an editor opened by 'git commit'. Please make sure all processes  
remote: are terminated then try again. If it still fails, a git process  
remote: may have crashed in this repository earlier:  
remote: remove the file manually to continue.

But I don't know how I can access the remote to delete the file?

I can see others on here with similar problems but I didn't find a resolution...

UPDATE:

I can still work with the repository in other ways - I've branched develop to a temporary branch for now.

Is my best bet is to delete the remote branch and push again?

UPDATE TWO:

For future reference: Issues like this require access to the remote repo to resolve properly, so it requires support from Atlassian.

For free plan users (like me) the best way to get that support is via this community board.

Thanks everyone!


Answers:
author: Caroline R
body: Hi, [@Joe Dahl-Fisher](/t5/user/viewprofilepage/user-id/4741474), welcome to the community!

As we will need to access the repository to remove this lock file, I went ahead and created an internal ticket for you using the email of your community account, so you don't have to share this information here.

You should have received an email with a link to the support ticket. Just in case you haven't received it, please feel free to let me know and I can post the ticket URL here. The ticket will be visible only to you and Atlassian staff, no one else can view its contents even if they have the URL.

Please let me know if you have any questions.

Kind regards,  
Caroline

comments: author: Joe Dahl-Fisher
body: Thanks Caroline, I've been in contact with support and the problem is now resolved.


author: Erik_Lopez
body: I am getting this same issue now. Who can I contact for support?


author: sonalilotankar
body: Soln:

Step 1: remove mentioned reference

rm .git/refs/heads/develop

Step 2: git fetch

Step 3: git pull

comments: author: cameron
body: This does not work. Please don't submit false solutions stating they "will work 100%" as it has the potential to ruin some peoples working environment.


author: sonalilotankar
body: Hey, I've updated the comments.

But in my case, whenever i faced this issue i used to follow above mentioned steps and it works in my case.

Apologies..


author: Joaquim Monteiro
body: This solution was the only one that worked for me, just you have to update the path to target your affected reference. also note the '.git'

thanks mate.


author: Vishwas
body: Hey [@Joe Dahl-Fisher](/t5/user/viewprofilepage/user-id/4741474)

Welcome to Atlassian Community !!

Try running below command in git bash inside that repository folder.

First one shows what happens to the repo before doing an actual command which is second one.

```
git remote prune origin --dry-run
```

    git remote prune origin

Let me know how it goes.

Regards,

Vishwas

comments: author: Joe Dahl-Fisher
body: Hey, thanks for getting back to me. No luck unfortunately! The command doesn't seem to find anything to prune.


author: Vishwas
body: Can you send me a screenshot so that i can understand better.

Also did you do git gc ? that was another method to fix.


author: Joe Dahl-Fisher
body: Here is the output from my shell:  
joe@Joes-MacBook-Pro maya_utils % git remote prune origin --dry-run  
joe@Joes-MacBook-Pro maya_utils % git remote prune origin  
joe@Joes-MacBook-Pro maya_utils % git push  
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0  
remote: error: cannot lock ref 'refs/heads/develop': Unable to create '...././refs/heads/develop.lock': File exists.

remote:  
remote: Another git process seems to be running in this repository, e.g.  
remote: an editor opened by 'git commit'. Please make sure all processes  
remote: are terminated then try again. If it still fails, a git process  
remote: may have crashed in this repository earlier:  
remote: remove the file manually to continue.


author: Joe Dahl-Fisher
body: I tried GC too, but it didn't help

I wonder if the best option is just to delete the remote develop branch and push the local again? Given that its currently me using this repo...


Tags: atl-gruland

bitbucket-cloud

cloud