Pete
Pete

Reputation: 12553

How do I delete a branch with the name starting with '-'

In an attempt to create a tracking branch I have managed to create a local branch named '-t'. I cannot delete the branch because the branch name is also a parameter. This is on a windows machine.

$ git branch -D -t
fatal: branch name required

Escaping doesn't help either

$ git branch -D \-t
fatal: branch name required

Placing the branch name in quotes does not help either

$ git branch -D "-t"
fatal: branch name required

Using the git gui to try to delete the branch gives the same error message.

I was thinking of just deleting '-t' from .git/refs/heads - Is that enough? Or is there more to it than that? Or is there a way that can delete it from the command line?

Upvotes: 6

Views: 1660

Answers (1)

Gabriele Petronella
Gabriele Petronella

Reputation: 108091

Use the -- option

git branch -D -- -t

As you can read here

a double dash (--) is used in bash built-in commands and many other commands to signify the end of command options

Git won't treat -t as an option anymore, since it comes after the --.

Upvotes: 10

Related Questions