David - ACA Group
David - ACA Group

Reputation: 509

How to solve '.git/index.lock': No such file or directory' error?

Summary

I recently lost the ability to make any changes using Git on my Windows system. After a few days of not using my PC I come back to a non functional git so I have no idea what caused this issue.

Examples:

git add or git checkout => fatal: Unable to create 'dummy-repo/.git/index.lock': No such file or directory

git clone => fatal: could not create work tree dir 'DummyRepo': No such file or directory

As a side note, this problem occured after trying to start my Flutter application, which could not retrieve the packages because of an OS error where access was denied. I'm thinking this is either because of some write permissions being messed up or a certain process locking a file.

What I've tried so far:

Any help is appreciated!

Upvotes: 6

Views: 3883

Answers (4)

Sherman Chen
Sherman Chen

Reputation: 329

I did 2 things:

  1. I found that there was a file named 'index' in '.git/' directory. I made a copy of it, and renamed the copy as 'index.lock'.
  2. Under 'Ransomware protection', I temporarily switched off 'Controlled folder access'.

Problem solved.

After I am done, I switched 'Controlled folder access' back on.

Upvotes: 0

the_nuts
the_nuts

Reputation: 6064

On Windows, this may happen if you enabled the "Ransomware protection" in Setting > Windows security > Virus & threat protection.

You need to add an exclusion for git.exe, or move the project outside a protected folder.

Upvotes: 20

David - ACA Group
David - ACA Group

Reputation: 509

I've solved it myself by changing the location of my project to C:\ instead of a way longer path. This was never a problem before but it works so I'm happy.

Upvotes: 3

mirkancal
mirkancal

Reputation: 5385

Try creating that file in your .git directory, you can use these commands in Git Bash or linux/mac

cd .git
touch index.lock

On Windows CMD

cd .git
type nul > index.lock

Upvotes: -1

Related Questions