It’s probably safe to say that anyone who has ever used git has struggled with it in one way or another. My most vexing problem has been the (apparently common) issue where git cannot create the index.lock
file. In my case, this has happened while trying to update my fork by pulling from the upstream master repo.
Here’s the error I get:
Naturally, the first thing I did was run git status
. Here’s what it showed:
Aha! I just need to add and commit the changes to these files, and all will be well. With that done, let’s try pulling again and hopefully all will be fine. Except, it didn’t work at all.
Now, here’s the part where I’m going to skip over a few of the intermediate steps. This is partly because I don’t remember exactly what I did, but more importantly I don’t want you to try the same thing because it failed miserably for me. Net/net, I had to create a new local repo, re-fork the master, and manually copy over my files.
Instead, here is what you do if you encounter this error with index.lock
:
Open a terminal window and navigate to the top folder of the repo where the issue is occurring. At the prompt ($), type:
$ cd .git
Then type:
$ rm -f index.lock
Navigate up to the top folder:
$ cd ..
Now add and commit your changes:
$ git add .
$ git commit -m "Fixed lock file issue"
$ git push
Once you’ve done this, hopefully you will be good to go.