user1760561
user1760561

Reputation: 655

remove .git/index.lock': Permission denied

I'm completely stuck as to why my git has completely locked me out. I have a laptop that I use at work and when I'm home. For both accounts I use git extensively and both are located in different paths. Today I came into work and I can't do anything, all I see is:

/Applications/MAMP/htdocs/my_site/.git/index.lock': Permission denied

For all I care the branch I'm on can be deleted. I've tried removing the branch, checking out any other branch, removing the index.lock file (as suggested by other users on sites). I only have the terminal window open, no other possible programs using git (as far as I know and nothing noticeable in the activity window). I have rebooted the computer straight into my work account and still no luck. How can I remove this lock?

Upvotes: 51

Views: 116096

Answers (9)

Strider489
Strider489

Reputation: 67

If using Github Desktop, run the app as Admin.

Upvotes: 0

pedrommuller
pedrommuller

Reputation: 16056

Change the permissions from root to the current user for the /.git folder

sudo chown username .git

Upvotes: 3

daidai21
daidai21

Reputation: 378

My computer system is Windows. When I open WSL remote vscode and local vscode in this path, system show this error. I closed remote vscode WSL and it solved this problem.

Upvotes: 3

Mahshid Zeinaly
Mahshid Zeinaly

Reputation: 3978

I had the exact same problem wanting to commit my changes to git, and solved it this way:

  • I needed to change the group of my .git folder and its contents:

    sudo chown -R <owner>:<group> .git

  • needed to change the permission of this folder:

    sudo chmod -R 775 .git

Upvotes: 69

MrsPop88
MrsPop88

Reputation: 303

I had this issue as I running the following command sudo git fetch && git checkout<branch>

Note the second sudo was missing. Running the following solved the issue: sudo git fetch && sudo git checkout<branch>

You shouldn't have to change the owner ship of the .git directory when running sudo.

Upvotes: 7

Diego Pino
Diego Pino

Reputation: 11586

I was experiencing the same issue when trying to update the submodules of my repo:

$ git submodule update
fatal: Unable to create '.../.git/modules/deps/luajit/index.lock': 
   Permission denied
Unable to checkout '04dc64b558025e76a820f89a8e41840bf8269f32' in
   submodule path 'deps/luajit'

It seems the problem was the submodules belonged to a different user, so I set back the ownership to me:

cd .git/modules/
chown -R user.group *

Upvotes: 3

Augusto
Augusto

Reputation: 2222

Checking permission is surely the way. I faced this error when logged in with the wrong account. So, answer from my personal experience is:

"Be sure you logged in with the correct account".

Upvotes: 1

Matthias M
Matthias M

Reputation: 14830

After updating xcode you are maybe asked for agreeing to the new license.

git init

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

When you do this

sudo git init

you'll get a root user .git dir

drwxr-xr-x 10 root XXXX 340 25 Sep 12:40 .git

If you call other git commands which create files, these files are also created for the root user.

Change the permissions or remove .git if you don't need it yet.

=> Don't ever call git with sudo!!! If your are asked to just call git on an empty directory

mkdir foo

cd foo

sudo git init

Upvotes: 10

Jure C.
Jure C.

Reputation: 3080

Check which user owns the git lock:

ls -la /Applications/MAMP/htdocs/my_site/.git/index.lock

Then you can use sudo to remove it.

Upvotes: 27

Related Questions