Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists

Solution 1:

Try

rm -f ./.git/index.lock

In your repository directory. The error message is rather explicit as to what causes it typically, so if you have no other git processes running (which is the normal case), go ahead and delete that file.

Solution 2:

In Windows, do this in the command prompt from the repo directory:

cd .git
del index.lock

UPDATE: I have found that I don't need to do this procedure if I wait a moment after I close out the files I'm working on before I try to switch branches. I think sometimes this issue occurs due to git catching up with a slow file system. Other, more git-knowledgeable developers can chime in if they think this is correct.

Solution 3:

Try quitting Xcode - since it's a git client, you have to quit Xcode to avoid problems with git on the command line.