4

When I try to run any git command, I get the following

$ git add .
 fatal: Unable to create 'J:/Project/geospatial/U5M_africa/.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 remove the file without any errors:

$ rm -f .git/index.lock

I also try to remove this manually in windows. The file disappears, but re-appears immediately. If I try any git commands I still get the same fatal error.

What is causing the file to instantly re-appear? How can I get rid of it for good and get on with my life?

royburst
  • 73
  • 1
  • 5

5 Answers5

2

My not so elegant, but effective solution:

Rename the file first, then delete it. For some reason, this works ..

royburst
  • 73
  • 1
  • 5
0

Check your processes (with process explorer: CTRL+F: search for J:\Project\geospatial\U5M_africa)

You must have a process writing in your repo, and causing git to create that file.
It can be a git gui, or any other process as commented in "git index.lock File exists when I try to commit, but cannot delete the file"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I've tried that with no luck. The file that gets re-written does get re-written with the old timestamp which is fishy.. – royburst Jan 10 '16 at 06:41
  • @royburst if the file re-appear automatically, you should have a process which causes just that. – VonC Jan 10 '16 at 06:42
  • @royburst Maybe the anti-virus: try to exclude J:\ – VonC Jan 10 '16 at 06:42
  • @royburst what version of git are you using on Windows? Are you using cygwin? – VonC Jan 10 '16 at 06:43
  • I am using 2.6.3.windows.1, not using cygwin. – royburst Jan 10 '16 at 06:46
  • as mentioned by @VonC something is "locking" your git project and create this file. this file is usually created when you try to pull or push for example and should be deleted once the operation is over. – CodeWizard Jan 10 '16 at 06:53
0

As mentioned by @VonC something is "locking" your git project and create this file.

This file is usually created when you try to pull or push or when working with submodules and should be deleted once the operation is over.

As you found out - deleting it manually will also work, i was under the assumption that you already tried it and it being created over and over.


To summarize:

If this file is not deleted automatically by the git process you should delete it manually and it will work. This is what i do when i ran into this problem.

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.

The solution is very easy, just delete the .git/index.lock file

rm .../.git/index.lock
Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
0

Actually if remove lock file not worked properly(appearing every time) then their is a another git process was running in your machine may be git GUI or git Extension or anything else. Make sure you should close all git processed expect git bash. Then the git commands definitely will work without creating index.lock file problem.

0

I faced the same issue. Deleting index.lock manually or through the command (rm -f .git/index.lock) did not help. The file reappeared while I tried to switch branches.

I did a restart (MacOS) and did the delete manually, it worked.

Not sure if this is a good solution, but might help someone.

Apsara
  • 61
  • 6