(WSL2) git unable to create index.lock AND unable to unlink index.lock

Viewed 379

Problem

First this occurs whenever I do git add or git commit.

fatal: Unable to create '/mnt/d/xxx/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

Then, I removed the index.lock file, and this error occurs.

warning: unable to unlink '/mnt/d/xxx/.git/index.lock': Permission denied
fatal: unable to write new index file

After changing the index.lock to permission 755 (I also made sure I own this file), the error message went back to the one fatal: Unable to create '/mnt/d/xxx/.git/index.lock': File exists.

Basically this makes it a loop of errors and impossible to do any staging and commit. Even restarting the computer after removing the index.lock file did not work out.

  • However, I found a workaround by switching to cmd prompt and do the equivalent git add/git commit (but I would like to be able to work in WSL2).

Setup

  • the git project is created with WSL, but I did place it in a Windows directory. (it worked fine for a couple of days, and somehow this problem occurred today)
  • the ownership of the folders are correctly set to the current WSL user
  • there is no other process associated with git that is running except for my current session. (I checked in WSL with ps -fe and in powershell get-process)
0 Answers
Related