5

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

e.g.

$ git branch
* (no branch)
   -f

How do I delete the dang thing? git branch -d -f won't work, nor will git branch -d '-f' or even git branch -d -f -f

UsAaR33
  • 3,376
  • 2
  • 29
  • 54
  • 1
    possible duplicate of [Deleting a badly named git branch](http://stackoverflow.com/questions/1192180/deleting-a-badly-named-git-branch) – Josh Lee Apr 19 '11 at 03:45

3 Answers3

17
git branch -d -- -f

The -- symbol in general will stop parsing of command line options with many Linux tools.

Another way is

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

but git-update-ref is rather dangerous.

Josh Lee
  • 161,055
  • 37
  • 262
  • 269
4

Not sure if this will work, but a -- argument in Unix/Linux-style commands often tells the command that you're done passing options, and now you're passing real arguments:

git branch -d -- '-f'
Andy White
  • 84,168
  • 47
  • 173
  • 207
0

I foolishly named a branch starting with a hyphen, and then checked out master. I didn't want to delete my branch, I had work in it.

Neither of these worked:

git checkout -dumb-name

git checkout -- -dumb-name

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

This worked: go into your working copy's .git/refs/heads, find the filename "-dumb-name" (or whatever) and get the hash of the branch. Then:

git checkout {hash}
git checkout -b brilliant-name
git branch -d -- -dumb-name
Samuel Meacham
  • 10,035
  • 7
  • 43
  • 50