How to delete a git branch named "--track"

102 views Asked by At

I made a mistake when I checked out a new branch with git. git version 1.7.1

I ran git branch -b --track origin/develop and I got a branch named --track. How can I delete it?

What I have done:

$ git branch
--track
* develop
master

$ git branch -d --track
$ git branch -d "--track"
$ git branch -D --track
$ git branch -D "--track"
$ git branch -D '--track'
$ git branch
--track
* develop
master
3

There are 3 answers

0
phd On

Try

git branch -D -- --track

-- separates options from arguments.

0
torek On

The method in hobbs' answer will likely work. If that fails, you can use git update-ref to delete the branch name in a way that will also not start with -:

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

This should work even if the branch has gotten packed.

1
hobbs On

Rather than trying to figure out (if there is) a way to get the git tools to do it, you can simply

rm .git/refs/heads/--track