git · Git
The message
fatal: Unable to create '/repo/.git/index.lock': File exists.
What it means
git creates .git/index.lock as a lock while it writes the index, so the file already being there means another git is running or one died and left it. It is left behind by an editor or IDE running git in the background, or by a command you interrupted with Ctrl+C or killed. Make sure no git is running, then remove it with rm -f .git/index.lock. Deleting it while a git process is genuinely at work can corrupt the index, so check first; if the index does end up wrong, git reset rebuilds it from HEAD, and without --hard it leaves your files alone.
The fix
rm -f .git/index.lock- Printed by
- git
- Git
- 29
Almost every git error is a refusal that means "doing that from this state would lose something"; fatal: means git stopped without changing anything, and the hint: lines under the first line usually carry the actual remedy.
Reading an error message
- Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
- If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
- Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
- The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
- Before pasting a fix, check what it throws away. Some of these cannot be undone.
Common questions
Q. What does “fatal: Unable to create '/repo/.git/index.lock': File exists.” mean?
git creates .git/index.lock as a lock while it writes the index, so the file already being there means another git is running or one died and left it. It is left behind by an editor or IDE running git in the background, or by a command you interrupted with Ctrl+C or killed. Make sure no git is running, then remove it with rm -f .git/index.lock. Deleting it while a git process is genuinely at work can corrupt the index, so check first; if the index does end up wrong, git reset rebuilds it from HEAD, and without --hard it leaves your files alone.
Q. How do I fix it?
rm -f .git/index.lock — before running it, check the explanation above for what this command discards.
Q. Which tool prints this?
git. It sits under Git, and the message runs to 7 words.