I've been noticing this problem when I've been using git recently (last couple of months or more). I've been ignoring it because if I do the same command a 2nd time, it just works. However, it is starting to annoy me and am worried that it is some kind of bug.
The last time this happened I stashed what I was doing, attempted a rebase, which failed, so I aborted and then popped the stashed object. This resulted in getting the error. I did a 2nd pop and it worked. Here are the commands and their responses (with some specifics taken out).
# starting in branch 'my-branch'
$ git stash
Saved working directory and index state WIP on ...
$ git checkout develop
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
$ git pull
From https://...
...
$ git checkout my-branch
Switched to branch 'my-branch'
Your branch is up to date with 'origin/my-branch'.
$ git rebase develop
First, rewinding head to replay your work on top of it...
Applying: ...
D:/Projects/Dev_Git0/wp/.git/worktrees/wp4/rebase-apply/patch:23877: trailing whitespace.
// Microsoft Visual C++ generated resource script.
D:/Projects/Dev_Git0/wp/.git/worktrees/wp4/rebase-apply/patch:23878: trailing whitespace.
//
D:/Projects/Dev_Git0/wp/.git/worktrees/wp4/rebase-apply/patch:23879: trailing whitespace.
#include "resource.h"
D:/Projects/Dev_Git0/wp/.git/worktrees/wp4/rebase-apply/patch:23880: trailing whitespace.
D:/Projects/Dev_Git0/wp/.git/worktrees/wp4/rebase-apply/patch:23881: trailing whitespace.
#define APSTUDIO_READONLY_SYMBOLS
warning: squelched 23867 whitespace errors
warning: 23872 lines add whitespace errors.
Using index info to reconstruct a base tree...
M proj/RESOURCE.RC
Falling back to patching base and 3-way merge...
Auto-merging proj/RESOURCE.RC
CONFLICT (content): Merge conflict in proj/RESOURCE.RC
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch' to see the failed patch
Patch failed at ...
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
$ git rebase --abort
$ git stash pop
fatal: Unable to create 'D:/Projects/Dev_Git0/.git/wp4/worktrees/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 stash pop
On branch my-branch
Your branch is up to date with 'origin/my-branch'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: proj/RESOURCE.RC
Dropped refs/stash@{0} (fe4ad3ed7abaf235ff839f33861b840f76a54249)
$
Is anyone else having this issue or know why this would be happening? Is it related to me using worktrees? I'm not running any other git process on my computer.