gitチェックアウト時にindex.lockでエラーが発生したら

事象

ブランチを切り替えようと git checkoutしようとしたら下記のエラーが出てブランチの切り替えができない。 pullしたりfetchしたりしてみたが解消されず。

fatal: Unable to create 'ソースのパス/.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.

解決策

.git/index.lockを削除
私の場合はこれで解消されました。
ちょっと調べてみると下記のサイトでも同じようなことが書かれていました。

Gitでcommitとpull時にindex.lockのエラー - Qiita

.git/index.lockを削除してもだめな場合もあるようでしたら、 .git/.COMMIT_EDITMSGも合わせて削除すると解消されるとのこと。