Software⏱️ 2 min read📅 2026-05-30

How to Fix: Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists

Git error when trying to init repository due to existing index.lock file.

Quick Answer: Try deleting the .git directory and then run git init again.

The error you're encountering occurs because the Git process is already running, but it's not visible to your terminal. This usually happens when another user or a background process has initiated a Git operation on the same directory.

💡 Why You Are Getting This Error

  • [Cause]

🛠️ Step-by-Step Verified Fixes

Method 1: Force Git to Create the Index Lock File

  1. Step 1: Run the following command in your terminal: `git -C /path/my_project fetch --force`

Method 2: Delete the Existing Index Lock File

  1. Step 1: Navigate to the project directory and run: `rm /path/my_project/.git/index.lock`

🎯 Final Words

Once you've fixed the issue, try running `git init` and `git add .` again to see if your project can be successfully initialized.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions