Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git index.lock File exists when I try to commit, but cannot delete the file

Tags:

git

This may be an old reply but I'm hoping this is more useful on next who need this solution.

On linux/unix/gitbash/cygwin, try

rm -f .git/index.lock

On Windows Command Prompt, try:

del .git\index.lock


For Windows:

  • From a powershell console opened as admin, try
> rm -Force ./.git/index.lock
  • If that does not work, you must kill all git.exe processes
> taskkill /F /IM git.exe
SUCCESS: The process "git.exe" with PID 20448 has been terminated.
SUCCESS: The process "git.exe" with PID 11312 has been terminated.
SUCCESS: The process "git.exe" with PID 23868 has been terminated.
SUCCESS: The process "git.exe" with PID 27496 has been terminated.
SUCCESS: The process "git.exe" with PID 33480 has been terminated.
SUCCESS: The process "git.exe" with PID 28036 has been terminated.
> rm -Force ./.git/index.lock

On a Windows platform running Visual Studio 2015 RC (v4.6.00057) in combination with SourceTree (v1.6.14.0) will give this error as well.

Solution: Assuming you want to use source tree as source code manager, simply disable the source control provider inside Visual Studio like this:

  1. Go to: Tools > Options > Source Control
  2. Select Current source control plug-in as: None

  1. check if the git still running (ps -ef | grep git)
  2. if not, remove the locked file
  3. if yes, kill the git process at first.