I'm trying to delete my local branch and tried most of the solutions I found on here which is to checkout to another branch and then run git branch -D (or -d) <my_branch>
. I tried that but I am still getting the same error that states "Cannot delete branch 'my_branch' checked out at 'my_path'
How I got myself in this situation: I branched off of my develop branch by doing git worktree add -b branch_name ../project_name develop
. Then I realized I wanted to change my branch name so I deleted the entire directory first by using rm- rf
. Now my_path is pointing to a deleted directory so I'm not sure what to do now. Help will be appreciated. I'm running on Windows 7 using Git Bash
Things I have tried:
git branch -d
and git branch -D
Screenshot of error:
The (virtualBDD) is my virtual environment. You can ignore that.
Did a bit more browsing and came across this answer that uses git worktree prune
to remove information on (non-locked) worktrees that no longer exist. This essentially removed my worktree from git worktree list
and then I proceeded to do git branch -d my_branch
. This solved my issue. Thanks to everyone that helped.