[git] Deleting a local branch with Git

I've googled and there are several very long threads on this topic and none of them seem to help. I think I'm doing something wrong. I have a branch called Test_Branch. When I try to delete it using the recommend method, I get the following error:

Cannot delete branch 'Test_Branch' checked out at '[directory location]'.

I get no other information besides that. I can blow away the remote branch easy but the local branch won't go away.

This question is related to git

The answer is


You probably have Test_Branch checked out, and you may not delete it while it is your current branch. Check out a different branch, and then try deleting Test_Branch.


This worked for me...
I have removed the folders there in .git/worktrees folder and then tried "git delete -D branch-name".


If you have created multiple worktrees with git worktree, you'll need to run git prune before you can delete the branch


In my case there were uncommitted changes from the previous branch lingering around. I used following commands and then delete worked.

git checkout *

git checkout master

git branch -D


Like others mentioned you cannot delete current branch in which you are working.

In my case, I have selected "Test_Branch" in Visual Studio and was trying to delete "Test_Branch" from Sourcetree (Git GUI). And was getting below error message.

Cannot delete branch 'Test_Branch' checked out at '[directory location]'.

Switched to different branch in Visual Studio and was able to delete "Test_Branch" from Sourcetree.

I hope this helps someone who is using Visual Studio & Sourcetree.


Ran into this today and switching to another branch didn't help. It turned out that somehow my worktree information had gotten corrupted and there was a worktree with the same folder path as my working directory with a HEAD pointing at the branch (git worktree list). I deleted the .git/worktree/ folder that was referencing it and git branch -d worked.