Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't delete local git branch

So, I was deleting a local branch with the command git branch -D and after deleting the branch, a new branch, named '-D' showed up in my local repo. So now when I run 'git branch' there is a branch called '-D'.

Unfortunately, when I try to delete this branch, using 'git branch -D -D', I get a 'fatal: branch name required' error.

Any ideas how to get rid of this branch?

like image 290
theCuriousGee Avatar asked Jul 10 '26 06:07

theCuriousGee


1 Answers

You can try:

git branch -D -- -D

Where -- is a fairly common syntax for "stop interpreting - as introducing an option after this point". This seems to work in my test:

$ git branch
  -D
  foo
* master
$ git branch -D -- -D
Deleted branch -D (was 460317a).

If that doesn't work, you could try to delete .git/refs/heads/-D if it exists.

like image 170
larsks Avatar answered Jul 16 '26 01:07

larsks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!