git エラー「fatal: Unable to create ‘xxx/.git/index.lock’: File exists.」が発生した場合の対処法

  • 作成日 2022.10.31
  • git
git エラー「fatal: Unable to create ‘xxx/.git/index.lock’: File exists.」が発生した場合の対処法

gitでエラー「fatal: Unable to create ‘xxx/.git/index.lock’: File exists.」が発生した場合の対処法を記述してます。「index.lock」が存在する間に「commit」などのコマンドを実行すると発生します。gitを使用している環境はwindows環境となります。

環境

  • git version 2.24.0.windows.2

エラー内容

「git commit」実行に発生しました。

>git commit -m "Initial commit"

fatal: Unable to create 'xxx/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

原因

「index.lock」が残ったままになっていたため。
※他の人が作業している可能性もあります。

対処法

他の人が作業してなさそうであれば「index.lock」を削除すれば解決します。