Home › Git

fatal: Unable to create '.git/index.lock': File exists. — how to fix

fatal: Unable to create '/home/me/project/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

Quick fix: Close editors/IDEs running git, check ps aux | grep git, then remove the stale lock: rm -f .git/index.lock (Windows: del .git\index.lock).

What it means

Git writes .git/index.lock while it modifies the index (staging area) so two processes can't corrupt it at once. When the process finishes, the lock is deleted. If git crashed, was killed, or another tool is running git in the background, the lock stays and every new command refuses to run.

Fix

  1. Check nothing is still running. Common culprits: an open git commit editor, VS Code / JetBrains source control, GitHub Desktop, a git gc in the background.

bash ps aux | grep -i git

  1. Remove the stale lock:

bash rm -f .git/index.lock

Windows (cmd / PowerShell):

powershell del .git\index.lock Remove-Item .git\index.lock

  1. Run your command again.

Other lock files

The same message can name a different file, e.g. .git/refs/heads/main.lock, .git/HEAD.lock or .git/config.lock. The fix is identical: make sure git isn't running, then delete the named .lock file.

It keeps coming back

Last updated 2026-10-27.