Unable to create 'D:/project/xxx/.git/index.lock': File exists.
Problem Description
When using git to submit code or switch branches, an error of Unable to create 'D:/project/xxx/.git/index.lock': File exists. appears, as shown below:
Unable to create 'D:/project/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.
Git will automatically generate an index.lock file when performing an operation, and it will be automatically deleted after the operation is completed. The purpose of this is to avoid operating the same folder at the same time. The reason for the above error is that the index.lock file is not automatically deleted due to some reasons (for example, the operation is too fast, the previous step process is not completed, and the next step operation will start)
Solution
In fact, it is very simple to solve this problem, just delete the index.lock file in the .git directory,
and then you can execute git commands normally, such as submitting, switching branches, etc.