fatal: unable to create 'refs/heads/master.lock': File exists fatal: - Getting this error while pushing the commits
Asked Answered
M

5

21

I am getting the following error while pushing the commit

$ git push origin master
fatal: unable to create 'refs/heads/master.lock': File exists fatal:
The remote end hung up unexpectedly

I thought of removing the lock file (refs/heads/master.lock) from my local machine. But this file is not available. I think this file is in git server.

What is the origin of this issue? If I remove this file from the server, will it solve the issue if the file exists?

Mccarthy answered 14/12, 2011 at 6:0 Comment(1)
Did the answers really do the trick? According to your question the file didn't exist, then how did you remove a non-existing file?Daugherty
D
24

You need to remove existing .lock file and try to push,

Linux

rm -f .git/refs/heads/master.lock

Windows

del .git\refs\heads\master.lock
Dyche answered 10/11, 2014 at 5:25 Comment(1)
It should be rm -f .git/refs/heads/master.lockComical
L
7

It is because some other git operation might have died ( or even still running in the rare ) in the middle and left a lock file. Once you see that no git related process is running on the server, just to be safe, you can delete the file and try to push again.

Lynnelle answered 14/12, 2011 at 6:6 Comment(1)
How to remove it?Travelled
B
2

For those who come to this page with this problem but can't use the accepted solution because the file doesn't exist to be deleted, it's probably a permissions issue.

This SO question should be helpful. In my case I had been working with both root and a normal user account on different terminals and must have done something as root and caused problems like is suggested in the linked answers. Solution was to fix permissions in my git directory back to the user.

Byelaw answered 25/9, 2017 at 15:41 Comment(0)
T
0

Like another answer posted here says, it can be a permissions issue. In my case I had to login to the server as the user used to push the code. Then I had to cd to the parent directory of the directory used to push the code, and finally I had to change owner of the aforementioned directory.

sudo chown -R usernameHere gitDirectoryName
Teacake answered 13/7 at 18:49 Comment(0)
B
-4

I just used 'sudo' before my commit and it worked. I.e. "sudo git commit -am'commit message'"

Balbinder answered 25/1, 2017 at 3:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.