6

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,536
  • 2
  • 34
  • 55
  • 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

4 Answers4

18
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
  • 171,072
  • 38
  • 269
  • 275
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
  • 86,444
  • 48
  • 176
  • 211
2

I created a branch accidentally with the following:

git branch –show-current

I was able to use grep and xargs to specify a unique pattern to delete it:

git branch | grep "show-current" | xargs git branch -D
Javad
  • 2,033
  • 3
  • 13
  • 23
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,215
  • 7
  • 44
  • 50