I have a Git worktree associated with a branch that was somehow deleted.
Nothing seems to work.  git status is reporting Initial commit.
I have uncommitted changes. How can I get things back to normal in this worktree?
I have a Git worktree associated with a branch that was somehow deleted.
Nothing seems to work.  git status is reporting Initial commit.
I have uncommitted changes. How can I get things back to normal in this worktree?
Git attempts to prevent you from deleting branches that are currently checked out in any worktree.
However, with some versions of Git-related tools, it may be possible to delete a checked-out branch (I have done it while using gitk launched from a different worktree).  If this happens, the worktree will become confused and you will see message like unknown revision HEAD and bad revision 'HEAD'.  Normal recovery tools such as gitk --all and git stash become disfunctional due to this confusion.
Your best bet for salvaging the worktree (especially in case you have uncommitted work) is to perform a checkout of the exact revision that was previously associated with the branch.  One way to enable this is to run gitk --reflog (which works even though gitk --all does not) and recreate the branch at the correct location.
Once you have recreated the branch, you can check it out and resume your work.
Of interest: Why does git worktree add create a branch, and can I delete it?