[git] Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists

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?

This question is related to git

The answer is


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


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

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.


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.


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


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.


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

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


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


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.


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.


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

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.


For me it was

rm -r .git-credentials.lock 

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.


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

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"

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


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


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.


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

cd .git
rm index.lock

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


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.


Use This:

rm -Force ./.git/index.lock

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

Command:

sudo rm -rf .git/index.lock


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.


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.


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


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.


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.