Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists
GitGit Problem Overview
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?
Git Solutions
Solution 1 - Git
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.
Solution 2 - Git
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.
Solution 3 - Git
Try quitting Xcode - since it's a git client, you have to quit Xcode to avoid problems with git on the command line.
Solution 4 - Git
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.
Solution 5 - Git
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
Solution 6 - Git
> 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.
Solution 7 - Git
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
Solution 8 - Git
-
Run Task Manager, Locate Git for windows process and kill it.
-
Delete index.lock file under .git folder
-
It worked for me !
Solution 9 - Git
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
Solution 10 - Git
In Mac OS X do this in the command prompt from the repo directory:
cd .git
rm index.lock
Solution 11 - Git
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
Solution 12 - Git
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
Solution 13 - Git
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 GIT
from merging.
Solution 14 - Git
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.
Solution 15 - Git
The solution that worked for me was closing sublime text because the running git process was initiated by the editor.
Solution 16 - Git
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.
Solution 17 - Git
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.
Solution 18 - Git
Use This:
rm -Force ./.git/index.lock
Solution 19 - Git
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.
Solution 20 - Git
You have problem with .git/index.lock
so delete it using below command.
Command: > sudo rm -rf .git/index.lock
Solution 21 - Git
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"
Solution 22 - Git
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.
Solution 23 - Git
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.
Solution 24 - Git
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.
Solution 25 - Git
For me it was
rm -r .git-credentials.lock
Solution 26 - Git
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
Solution 27 - Git
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.
Solution 28 - Git
simply go to D:/project/androidgc/.git/ this directory and delete index.lock this worked for me.
Solution 29 - Git
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
Solution 30 - Git
A little adding because I had to use different answers to get the actual solution (for me).
This did it for me:
- Open branch you are working on
- Open terminal (I use terminal in Git GUI)
- Typ in command:
cd .git
- 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
.
Solution 31 - Git
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
Solution 32 - Git
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
Solution 33 - Git
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: https://stackoverflow.com/q/9282632/3487604