If you have been using Git long enough, you have probably seen this scary looking error:
error: Unable to create '.git/index.lock': File exists.
Another git process seems to be running in this repository.
It usually shows up when you try to pull, merge, or commit, and Git refuses to continue. It can look confusing, especially if you are sure there is no other Git command running.
Let’s understand what it actually means and how to fix it safely.
What is the .git/index.lock file?
Inside every Git repository, there is a hidden .git folder. It holds the internal data Git needs to track everything in your project.
When Git starts a write operation such as git add, git commit, or git pull, it temporarily creates a file called .git/index.lock.
This lock file tells Git: “Someone is currently modifying the index, do not let anyone else do it at the same time.”
It is a simple safety mechanism that prevents corruption if two Git commands run together.
If the operation completes successfully, Git removes the lock file automatically.
But if your terminal crashed, your editor froze, or your computer was shut down mid-operation, that lock file may remain there. When you try another Git command, it sees the existing lock and refuses to continue.
Step 1: Check if a Git process is still running
Before deleting anything, make sure a Git process is not genuinely active.
Run this command:
ps aux | grep git
If you see something like git pull, git merge, or git commit running, wait for it to finish.
If it looks stuck, you can safely terminate it:
kill -9 <process_id>
Replace <process_id> with the number shown in the first column of the output.
Step 2: Remove the leftover lock file
If no Git process is running, remove the lock file manually:
rm -f .git/index.lock
That’s it. This command deletes the leftover file and frees Git to continue.
Step 3: Verify everything is fine
Run a quick check to see if your repository is healthy:
git status
If it shows your branch and file changes normally, you are good to go.
Then you can safely continue with your work:
git pull
When the problem keeps coming back
Sometimes, a background process such as an editor, a file watcher, or a Git hook keeps creating locks.
Here are a few tips if the error keeps reappearing:
Close your editor
Visual Studio Code, JetBrains IDEs, and some Git GUIs may keep background Git processes running.Restart your terminal
Old shell sessions can sometimes hold onto file handles.Rebuild the index
If the index itself got corrupted:
git reset
- Run Git garbage collection To clean up leftover internal files:
git gc --prune=now
git fsck
These commands are safe and help Git refresh its internal state.
Bonus tip: Preventing lock issues
- Avoid running multiple Git commands on the same repository at once.
- Don’t interrupt a Git command that is writing data.
- Keep your terminal or IDE from closing while a commit or pull is in progress.
Simple habits like these save you from a lot of frustration.
Final thoughts
The .git/index.lock error looks intimidating, but it’s actually Git doing its job to protect your data.
In most cases, it just means a previous Git process didn’t finish cleanly.
By checking for active processes, removing the lock file, and keeping your workspace tidy, you can get back to coding in less than a minute.
If you’ve ever struggled with repetitive tasks, obscure commands, or debugging headaches, this platform is here to make your life easier. It’s free, open-source, and built with developers in mind.
👉 Explore the tools: FreeDevTools
👉 Star the repo: freedevtools

Top comments (0)