1

I have accidentally created a local branch called -delete

When I try to run commands to delete the branch using

git branch -d -delete git branch -D -delete git branch --delete -delete 

It does not work and gives the error message back that says this:

error: did you mean `--delete` (with two dashes ?) 

How can I delete the '-delete' branch?

3 Answers 3

3

git branch also honors the -- convention : if you pass -- alone as an argument on the command line, anything after that will not be interpreted as an option.

Starting from @torek's setup in his answer :

$ git branch delete && mv .git/refs/heads/delete .git/refs/heads/-delete $ git branch -delete * master $ git branch -d -delete # fails error: did you mean `--delete` (with two dashes)? $ git branch -d -- -delete # works Deleted branch -delete (was cec927c). $ git branch * master 
Sign up to request clarification or add additional context in comments.

Comments

2

No user-oriented Git command should have let you create that branch name in the first place (I had to resort to trickery to set up the condition myself, as I didn't think to use git update-ref right off), but once you have it, the way to get rid of the bad name is to use git update-ref:

git update-ref -d refs/heads/-delete 

Here's my example:

$ git branch delete $ mv .git/refs/heads/delete .git/refs/heads/-delete $ git branch -delete diff-merge-base * master $ git branch -d -delete error: did you mean `--delete` (with two dashes)? $ git update-ref -d refs/heads/-delete $ git branch diff-merge-base * master 

7 Comments

You can create it with update-ref, git update-ref refs/heads/-delete HEAD. Then of course git update-ref -d refs/heads/-delete.
Oddly enough. the -delete branch is still there... I am also surprised I created the branch in the first place. I'm sure I ran something simple along the lines of 'git br -delete'. Could it be some Eslint config? It is a huge codebase.
@jthill: ah, yes, of course. I was experimenting with "user oriented" ones first and didn't think to use it to create the branch, since nobody would use git update-ref directly like that.
@Jake.K: eslint shouldn't be going around creating branch names in the first place.
Am I going to have to break out my best Mel Blanc voice here?
|
0

I had the same problem. The only way that I found was to delete it by git GUI.

1- Right click in your project directory and then click on git GUI here 2- From the navbar click on branch then click on delete 3- choose the branch from the local branches box and the second box below, then click on the delete

Done enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.