How to resolve Git permission denied /.git/index.lock

6.4k Views Asked by At

I'm logged in as an admin user but cannot checkin files into a git repository. I keep getting:

fatal: Unable to create '.../.git/index.lock': Permission denied

I did try ls -la .git/index.lock but get a not exist error.

I haven't found anything to fix this. Does anyone have some suggestions?

4

There are 4 best solutions below

0
4thSpace On BEST ANSWER

After running several command lines with no luck, I deleted the index.lock file. Then ran more commands with no luck. Then I deleted the local repository and downloaded again. This time everything is working and I can check in files.

2
Anubhav On

The quick way is to delete the file.

cd <repo-dir>
rm -rf .git/index.lock

You may want to setup the permissions properly.

sudo chown -R <owner>:<group> .git # set group
sudo chmod -R 775 .git # access rights

From internet search

When you perform a Git command that edits the index, Git creates a new index.lock file, writes the changes, and then renames the file. The index.lock file indicates to other Git processes that the repository is locked for editing.

0
M Karimi On

Try deleting index.lock file in your .git directory.

0
Piumaster On

I tried to change the permissions; however, every time the action was executed, the permissions were changed. The only way I found was to delete the index file.

rm -rf .git/index