Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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?

like image 681
Pete Avatar asked Nov 17 '13 18:11

Pete


People also ask

How do I get rid of remote branch?

Deleting remote branches To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .

How do you delete branches which are not on remote?

Remove All Local Branches not on Remote First we get all remote branches using the git branch -r command. Next, we get the local branches not on the remote using the egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) command, Finally we delete the branches using the xargs git branch -d command.


1 Answers

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 --.

like image 159
Gabriele Petronella Avatar answered Oct 30 '22 11:10

Gabriele Petronella