fatal: Unable to create 'D:/Evi/Source/Git/.git/index.lock': File exists

Not every time, but quite often, I get this fatal error when trying to switch branches in my repository:

 

git -c diff.mnemonicprefix=false -c core.quotepath=false checkout <branch-name>

fatal: Unable to create 'D:/Evi/Source/Git/.git/index.lock': File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

 

I think the problems started after I updated the Git-for-Windows version from 1.9.5 to 2.5.x and prevailed in 2.6.x. Restarting SourceTree solves the issue (temporarily). I noticed that the latest SourceTree version 1.6.22.0 still downloads the 1.9.5 preview version when I try switching to  Embedded Git.

So, is this an incompatibility issue of SourceTree with Git-for-Windows 2.x? A Fix really would be appreciated since having to restart SourceTree gets quite annoying. The issue exists on multiple machines in our company.

2 answers

This error is really annoying and the error message is wrong. Any time I get this error message there is no index.lock file. If I open the Git Terminal from SourceTree and execute the same command the branch is switched correctly. As Rainer already mentioned the error is not permanent and can be worked around be restarting SourceTree.

My system git version is still at 1.9.5 and if I switch SourceTree to use this version changing branches works perfectly but then I can no longer access the Git bash terminal from SourceTree. I recently updated SourceTree to 1.6.23 and I did not encounter this problem in earlier versions.

I also get this error nearly every day.  If I watch the .git folder during an operation, I can see the index.lock briefly get created and then deleted.  It's a race condition in git and/or Sourcetree.

Also, it appears to be something that is actually caused by SourceTree because I don't get the problem if I use Git on the command line.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

989 views 2 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you