fatal: Unable to create '.git/index.lock': File exists
This error means another Git process holds the lock on your staging area, or a crashed process left the lock file behind. Nothing is corrupted and no work is lost. Here is how to clear it safely.
What this error means
Whenever Git updates the index (your staging area), it creates .git/index.lock as an exclusive lock, makes its changes, then removes it. If the file already exists when a command starts, Git refuses to run: either another process is genuinely working, or a previous process died before cleaning up.
Why this happens
Two Git processes at once
You ran a command while another was still working: a commit waiting for its message editor, a big rebase, or a second terminal on the same repository.
IDE or GUI in the background
VS Code, IntelliJ, SourceTree and friends run Git constantly for refreshes and auto-fetch. Their background operations can collide with your terminal commands.
A crashed process
Git was killed mid-operation (crash, closed terminal, reboot, out of disk space) and never removed its lock. The file stays behind and blocks everything.
How to fix it
First rule: never delete the lock while Git is actually running. Check first, then remove.
Check for running processes
An editor waiting for a commit message or an IDE mid-operation is the most common culprit. Finish or close them first.
Remove the stale lock
If nothing is running, the lock is a leftover. Deleting it is safe and loses nothing.
How to prevent it
One Git operation at a time
Let each command finish before starting the next, especially between your terminal and your IDE's Git integration.
Keep repositories on a local disk
Repositories inside Dropbox, OneDrive, or network shares are a classic source of lock conflicts: the sync tool touches files while Git works. Sync your code with Git remotes instead.
Do not kill Git mid-operation
Avoid closing the terminal or pressing Ctrl+C during commits, rebases, or merges. If a command seems stuck, check whether it opened an editor and is simply waiting for you.
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about index.lock
Understand what Git does under the hood
Index, staging area, lock files: GitQuest makes Git internals click through hands-on investigations in a safe terminal simulator.
Start practicing