Published on 2 min read
Git - How to Solve `’git/index.lock’: File exists` Error in Submodules
The Issue
So, you’ve a Git Submodule as part of your repository. Everything’s fine. But then – your task runner cleans up that submodule directory and for some reason – it’s removed. Suddenly, when you try to add changes to the staging area, it fails. Then, you figure out that you cannot perform the common Git commands because it keeps failing.
Thereafter, you decide to investigate the terminal and you face with that error:

If you’re familiar with this situation – you probably should keep on reading.
Note: I’m not a fan of hacky solutions, but the next steps solve the issue quickly. Follow these just in case you don’t know how to proceed with your issue.
The Solution
Disclaimer: I don’t take responsibility for the outcomes of your actions. You must back up your project before starting these steps.
Let’s assume the removed submodule directory was called "public".
So, the first step will be to navigate to the root directory of the repository. Then, we execute the following command for removing the temporary index.lock file:
rm -f .git/index.lock
Now, we verify there are no leftovers in the submodule directory:
rm -rf public
In the next step, we remove the submodule directory from Git index file:
git rm public
To end that, we reattach the submodule repository:
git submodule add -f -b master ORIGIN_REPOSITORY_URL public
Note: Replace ORIGIN_REPOSITORY_URL with the remote’s repository URL.
That’s all – the issue was solved. 😊
You’re welcome to share:
Enjoyed this post?
I’d love for you to follow me and join my newsletter.
Comments are powered by DisqusDetails
Loading comments activates Disqus, which collects information as a third-party service.
The site owner has no access to or control over the information collected by Disqus.
Related Posts

ECMAScript - Introducing Deferred Module Evaluation with import defer
8 min read
Introducing the “import defer” proposal, a new ECMAScript import form that loads and links modules eagerly while deferring their evaluation until a namespace property is first accessed - currently at stage 3 in the TC39 process.

ECMAScript - Introducing BigInt Primitive in ES2020 (ES11)
5 min read
Introducing the "BigInt" proposal, a new primitive of arbitrary precision integers, which has been reached stage 4 in the TC39 process and is included in the language specification of 2020 - the 11th edition.

ECMAScript - Introducing Dynamic Imports in ES2020 (ES11)
6 min read
Introducing the "Dynamic Import" proposal, arriving with new import() keyword enabling to load a module on demand at runtime, which has been reached stage 4 in the TC39 process and is included in the language specification of 2020 - the 11th edition.