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?

  • Permission denied (publickey) fatal: Could not read from remote repository. while cloning Git repository
  • how to reset develop branch to master
  • How to push changes to github after jenkins build completes?
  • git commit -m vs. git commit -am
  • In Git, how do you apply a commit of bug fix to the other newer branches?
  • Git: commit before merge?
  • Get commit list between tags in git
  • How to stage chunks non-interactively in git?
  • How to change the main branch in BitBucket?
  • What to add to “git status --porcelain” to make it behave like “git status”?
  • Git Subtree only one file or directory
  • hg equivalent of git add -p?
  • 4 Solutions collect form web for “remove .git/index.lock': Permission denied”

    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.

    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 : .git

    • needed to change the permission of this folder:

      sudo chmod -R 775 .git

    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

    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 dpino.dpino *
    

    In case of applying this snippet, remember to use your own user and group chown -R user.group *.

    Git Baby is a git and github fan, let's start git clone.