Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists
Asked Answered
W

35

1049

I am still getting this error message, when I try to move my project tree on to git repo.

I checked the permissions of my directory with this project and these are set on 777. In terminal in the directory with my_project I set:

git init

and then if I try

git add .

or

git commit -m "first upload"

so I'll get the error

fatal: Unable to create '/path/my_proj/.git/index.lock': File exists.

If no other git process is currently running, this probably means a git process crashed in this repository earlier. 
Make sure no other git process is running and remove the file manually to continue.

I tried also create a new repo and there to commit it, but unfortunately still the same error message.

What is the cause of problem?

Westbrook answered 22/10, 2011 at 16:3 Comment(5)
I had this issue because I logged in with su in a different terminal, switching back to the first everything went fineCernuous
#1367758Emf
bro i had the same problem , use "sudo git add . or git commit -m "first upload" " instead of " git add . or git commit -m "first upload" "Beckner
I got it fixed by changing permissions on .git file per #14127755 , refer to answer from Mahshid ZeinalyUzial
Similar-ish... if you can't create the index.lock, that means you have a full disk. If running thru WSL, empty some space on your windows harddrive and then run wsl --shutdown and try again.Gratia
G
2186

Try

rm -f ./.git/index.lock

In your repository directory. The error message is rather explicit as to what causes it typically, so if you have no other git processes running (which is the normal case), go ahead and delete that file.

Glockenspiel answered 22/10, 2011 at 16:6 Comment(23)
Thanks, that helped me. Now I run git commit -a and then I checked out git status, there was a message # On branch master nothing to commit (working directory clean). But I still don't see an imported files in my repo on bitbucket. In how time will be transfered the files from my local directory to web repo?Westbrook
It doesn't happen automatically. You need to execute the command git push to push your changes to the web server. Details on how this works are here: gitready.com/beginner/2009/01/21/pushing-and-pulling.htmlGlockenspiel
I'm having the exact same problem but I can't solve it this way because the .git/index.lock file doesn't appear to exist: touch .get/index.lock returns touch: .get/index.lock: No such file or directoryEnzymology
On closer inspection, I see a slight difference in the error message. Mine says :Permission deniedEnzymology
Emerson, you seem to be looking for .get instead of .git which would not exist.Itol
I had trouble with this, I used a similar command, with the '-f' from my home directory, I entered: "rm .git/index.lock"Schwab
i am running this command but still getting the same error /.git/index.lock': Permission denied Any clue? what else possibly needs to be done ?Sideboard
maybe i have a different git release, needed this: rm -Force ./.git/index.lockRoute
Permission denied means you need to give the user you are using Git with read/write permissions on the file. Check out chmod command (on *nix or Properties -> Security tab on WIndows)Liebermann
just fyi, in windows I did this:Etsukoetta
If your error says "Permission Denied", you have probably copied the files from somewhere else, and don't have permissions over the .git directory. Use ls -l to see permissions, then use sudo chown -R username ./*and sudo chgrp -R username ./* to change user and group to your own for all files in the project.Hotien
Years after this question was answered... your still saving peoples lives!Psychologism
In my case, that file doesn't exist either, the error message comes in the middle of a rebase. So there is no file I could remove and this seems like a "real" error.Gabor
i don't have .lock file under .git directory but still I am getting an error.Antiphon
No one actually reads the messages. It goes more like Oh, it failed. What do I do? hahaStrategist
@Itol .get is the Northern version. To be used solely when drinking Newkie Brown.Overturf
In my case, it was because I had a script to do some git-related stuff, and my editor was detecting a change of branch, and trying to reload changed buffers while the rest of my script was running.Parodic
@Gabor This file didn't seem to exist on my system either, but somehow running this command fixed it.Anastigmat
The error I am seeing is the same "fatal: Unable to create", Would that not be a permission issue in the .git folder? I don't have an index.lock file but still get the error.Fiedling
I had BitDefender which was blocking Git to make changes. I simply allowed Git to run from my BitDefener menu.Misconstruction
Its functional now after: Manually deleting the files from ./git/ directory. so no restrictions in deleting the file from console or view.Venn
'rm' is not recognized as an internal or external command,Ontology
For those like me that keep coming back to this issue; You can add this line as a shortcut for your (shell) terminal: alias rmlockfile='rm -f ./.git/index.lock'. Add it to your .zshconfig fileGoldfinch
E
198

In Windows, do this in the command prompt from the repo directory:

cd .git
del index.lock

UPDATE: I have found that I don't need to do this procedure if I wait a moment after I close out the files I'm working on before I try to switch branches. I think sometimes this issue occurs due to git catching up with a slow file system. Other, more git-knowledgeable developers can chime in if they think this is correct.

Etsukoetta answered 10/3, 2014 at 15:31 Comment(4)
Strangely enough, I get the error about the file but then when I try to delete the file in cmd.exe, it says file not found :) Same result with absolute and relative paths. But in Git Bash, it works (with rm -f index.lock)Cashbook
In my case, I executed "Fetch" after a couple of restarts of Sourcetree and worked.Vicarage
Though it won't be a problem in this case since we are dealing with a single file with 0 size, it is a better practice in general to use rmdir /s. del in cmd only removes files. Even then, without /s it won't recurse and will only remove files in the top-level directory. So, for cmd, you should be using rmdir /s to recursively delete all files and folders.Filbert
actually i have a react project, which needs to be uploaded everytime in the github, I always add it remotely, and i do it by "git init" but the problem is , there is already a .git file.., even though I delete that, this error still exists.Tyner
P
38

Try quitting Xcode - since it's a git client, you have to quit Xcode to avoid problems with git on the command line.

Polarity answered 23/7, 2012 at 19:22 Comment(2)
Nice! Note that Xcode AND other Git clients can be culprits. In my case it took closing gitX also.Euhemerus
After having to delete my lock file 10 times or so this morning I finally stumbled upon this answer. Don't know how xcode opened up but it was sure trashing my workflow. Thanks for the tip!Denning
C
36

I was having the same problem. I tried

rm -f ./.git/index.lock 

and the console gave me an error message. Then, I tried

rm --force ./.git/index.lock

and that worked.

Good Luck! This works super

Cointreau answered 13/5, 2015 at 22:54 Comment(2)
I dont see .git folder in my case. I only see ./ and ../ as far as hidden directory are concerns.Coldshoulder
What type of computer are you on?Cointreau
M
36

In my .git directory, there was no index.lock file. So, using the Git Bash shell, I ran...

cd .git
touch index.lock
rm index.lock

The touch command created the file, and the problem went away.

Metallist answered 25/5, 2016 at 20:55 Comment(11)
Why is this downvoted? I received the similar error message as OP. This fixed me, and maybe could help others.Metallist
I experienced a slight variant of this: (1) I experienced the error message and experimented with different 'fixes'; (2) I found that index.lock did not exist; (3) I used the above touch command; (4) my git client stopped functioning normally (at best, it slowed to a crawl); (5) I deleted index.lock; (6) the repository began functioning normally again.Viceroy
Definitely shouldnt be downvoted, sorted my problem out. I didnt have an index.lock file, but once I created one, and subsequently removed it, the commit worked.Objectivity
touch index.lock implies John was on *NIX, but I just did the equivalent on Windows 10 (create an index.lock file with a text editor, delete it immediately, and profit), and the problem's gone.Inserted
It's downvoted because it's missing the last step of deleting the index.lock file that you just created with touch.Naked
I keep getting No changes - did you forget to use 'git add'?Roseola
Though it's a bit weird, why you have to create it and then delete it? But this is the only solution that worked for me.Abduction
My Windows 10 with Git Bash working wellVaishnava
yep, this is what worked for me also. issue on mac os and vs codeStoneman
This is kind of absurd but it worked.Itu
I don't understand it, but it workedHungry
K
26

You need to delete the index.lock file.

In Linux

cd .git
rm -f index.lock

In Windows(10), do this in the command prompt from the repo directory:

cd .git
del index.lock
Kicksorter answered 13/10, 2021 at 10:55 Comment(0)
F
16

Did you accidentally create the repository using the root user?

It just happens that I created the git repository as the root user.

I deleted the git repository and created it again without sudo and it works.

Fraction answered 27/9, 2015 at 4:53 Comment(1)
Yeap, that's it. ThanksBitterweed
W
10

i have this problem too, and i find it really a permission problem. so i do this:

sudo chown -R : .git #change group
sudo chmod -R 775 .git #change permission

then ererything is great, and gaa is success.

and then i use gp, i get another error almost the same error

sudo chown -R "${USER:-$(id -un)}" . #use this can fix the problem
Warrantee answered 1/12, 2016 at 8:12 Comment(2)
brilliant, what does this do? "${USER:-$(id -un)}"Manifestation
Did not work on Windows 10 + git bash (even w/o the sudo)Persistent
B
9

In Windows, I only managed to be able to delete the lock file after Ending Task for all Git Windows (32bit) processes in the Task Manager.

Solution (Win 10)

1. End Task for all Git Windows (32bit) processes in the Task Manager

2. Delete the .git/index.lock file

Buffy answered 23/1, 2017 at 21:6 Comment(0)
P
9
  1. Run Task Manager, Locate Git for windows process and kill it.
  2. Delete index.lock file under .git folder
  3. It worked for me !
Pooh answered 16/3, 2021 at 13:42 Comment(0)
I
7

In Mac OS X do this in the command prompt from the repo directory:

cd .git
rm index.lock
Interconnect answered 12/4, 2016 at 3:29 Comment(1)
No such file or directoryJurisprudence
P
7

The solution that worked for me was closing sublime text because the running git process was initiated by the editor.

Protostele answered 16/9, 2016 at 22:46 Comment(1)
I've recently installed the Sublime Text plugin GitSavvy and had this error only since then. Thanks for the hint, @ProtosteleDisclosure
M
6

If after you try:

rm -f ./.git/index.lock

you get:

rm: cannot unlink 'index.lock': Permission denied

Try closing all software that might be using Git. I had Source Tree and Visual Studio opened and after closing both the command worked.

Mencher answered 13/10, 2016 at 8:39 Comment(0)
C
6

I think there's a better solution than removing the file (and god knows what will happen next when removing/creating a file with sudo):

git gc
Creamery answered 25/12, 2017 at 7:20 Comment(2)
Because it's windows? Try to use cmder or maybe use git kraken which maybe fix some stuffCreamery
in the middle of all these response all saying the same thing again and again (and ./.git/index.lock no existing), this solved my issue :)Elviaelvie
S
5

If you are using one of #intelliJ IDEs and receiving this msg (i'm using #webtorm), please notice that this problem can occur because of hiding one of project folders (inside settings), and this can prevent GITfrom merging.

Shreeves answered 18/2, 2015 at 12:16 Comment(0)
K
5

In my case the solution was to wait 5 minutes. Obviously my previous operation was still running but I just didn't know it. I was using tortoise git on windows.

Kenaz answered 20/4, 2015 at 9:27 Comment(0)
S
5

If it's a submodule, try this instead on your repository directory :

rm -f ../.git/modules/submodule-name/index.lock

change submodules-name to your submodule name.

Subside answered 12/3, 2018 at 10:12 Comment(0)
I
4

Use This:

rm -Force ./.git/index.lock
Injury answered 16/6, 2016 at 6:9 Comment(0)
M
3

DO NOT USE the Atom platformio-atom-ide-terminal Plugin to do this. USE THE TERMINAL OF YOUR DISTRO DIRECTLY.

I kept getting this error while rebasing/squishing commits and didn't know why because I had done it before several times.

Didn't matter how many times I would delete the index.lock file, every time it would fail.

Turns out it was because I was using the ATOM EDITOR terminal plugin. Once I used the terminal that ships with Ubuntu it worked like a charm.

Messidor answered 16/11, 2017 at 14:3 Comment(0)
S
3

You have problem with .git/index.lock so delete it using below command.

Command:

sudo rm -rf .git/index.lock

Soniferous answered 2/1, 2018 at 9:26 Comment(0)
W
3

I tried it with many methods several times but this one worked for me (I used PyCharm's terminal) :

$ cd .git/

$ rm -f index.lock

Then I tried again to create an empty git repo :

$ git init

$ git add .

$ git commit -m "commit msg"
Whisper answered 9/2, 2018 at 16:7 Comment(0)
F
2

The resolution for this problem is copying the three xcode/project files in the directory and then creating new directory (Whereever else) and then paste the three files/directories.

Frenzy answered 22/7, 2013 at 17:51 Comment(0)
A
2

Also we can just kill git process. I receive the same issue via GUI app for git, something goes wrong and git makes some work infinitely. Killing process will freeze application that works with git, just restart it and everything will be ok.

Antimony answered 4/7, 2014 at 11:12 Comment(0)
R
2

In case, for whatever reason, you are doing a rebase from a folder that's being sync'd by a cloud service (dropbox, drive, onedrive, etc), you should pause or turn off syncing as it will interfere with permissions during the rebase.

Ragtime answered 10/4, 2016 at 22:55 Comment(0)
I
2

For me it was

rm -r .git-credentials.lock 
Inerrable answered 29/5, 2016 at 21:47 Comment(0)
P
2

I had changed my directory permission so I knew it could be permission related. In my case I removed unwanted (_www) users and then applied read/write permission to everyone by apply changed to all contents. This is on Mac

Directory Permission on Mac

Photojournalism answered 4/11, 2016 at 7:7 Comment(0)
Y
2

All the remove commands didn't work for me what I did was to navigate there using the path provided in git and then deleting it manually.

Yacano answered 10/10, 2017 at 17:49 Comment(0)
S
2

In case someone is using git svn, I had the same problem but could not remove the file since it was not there!. After checking permissions, touching the file and deleting it, and I don't remember what else, this did the trick:

  • checkout the master branch.
  • git svn rebase (on master)
  • checkout the branch you were working on
  • git svn rebase
Slater answered 8/1, 2018 at 12:52 Comment(0)
T
2

A little adding because I had to use different answers to get the actual solution (for me).

This did it for me:

  1. Open branch you are working on
  2. Open terminal (I use terminal in Git GUI)
  3. Typ in command: cd .git
  4. Typ in command: rm -f index.lock

Some may have to use -Force instead of -f. You can check the command lines of your terminal by executing a command in your terminal something like: git help.

Towner answered 6/2, 2018 at 9:2 Comment(0)
M
2

simply go to D:/project/androidgc/.git/ this directory and delete index.lock this worked for me.

Mephitis answered 6/3, 2018 at 11:0 Comment(0)
L
0

All the solutions are right:

Just remove .git from your corrupted repository, 

then copy this file if back from another clone (if you don't have it in another machine, just clone it).

Finally, what made the difference to me:

  • Avoid using sudo to unzip or copy the new .git folder. Git won't have access to the .git folder if you use superuser rights to create it
Linwoodlinz answered 22/10, 2019 at 11:19 Comment(0)
V
0

I had this occur when I was in a subdirectory of the directory corresponding to the root folder of the repo (ie the directory in which .git was). Moving up to the root directory solved the problem - at the cost of making all file references a bit more inconvenient as you have to go path/to/folder/foo.ext instead of just foo.ext

Vosges answered 20/2, 2020 at 6:20 Comment(0)
P
0

A restart of the machine worked for me. None of the solutions provided so far worked for me.

Env Windows 10 + Git Bash

EDIT: I see the same solution was here: git index.lock File exists when I try to commit, but cannot delete the file

Persistent answered 26/8, 2020 at 23:14 Comment(0)
P
0

In my case, removing the lock file won't make it work.
Restarting the computer works for me

Pilgrim answered 20/11, 2023 at 3:47 Comment(0)
E
0

I Fixed this on Windows, my issue was the same but I needed to delete the HEAD.lock file as I didn't have an index.lock.

Eudocia answered 18/12, 2023 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.