Delete a branch starting with a hyphen

I managed to create a branch in git called '-f'

eg.

$ git branch * (no branch) -f 

How to remove a dang thing? git branch -d -f will not work, and there will be no git branch -d '-f' or even git branch -d -f -f

+4
source share
3 answers
 git branch -d -- -f 

Symbol -- in general, it stops parsing command-line options with many Linux tools.

Another way -

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

but git-update-ref pretty dangerous.

+13
source

Not sure if this will work, but the argument -- in Unix / Linux commands, often tells the command that you have finished passing the parameters, and now you pass the real arguments:

 git branch -d -- '-f' 
+3
source

I foolishly named a branch starting with a hyphen, and then checked the master. I did not want to delete my branch, I worked in it.

None of them worked:

git checkout -dumb-name

git checkout -- -dumb-name

" s, ' and \ didn't help either.

This worked: go into your working copy of .git / refs / heads, find the file name -dumb-name (or something else) and get the hash of the branch. Then:

 git checkout {hash} git checkout -b brilliant-name git branch -d -- -dumb-name 
0
source

All Articles