I know this isn't strictly a programming question, but it is related to git. I accidentally have created a branch in git called --track
(I got the order of options wrong when merging a remote branch)
The regular command doesn't work:
git branch -D "--track"
I have tried to escape with quotes and backward slashes, however neither work.
Any ideas?
Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.
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 .
The command to delete a local git branch can take one of two forms: git branch –delete old-branch. git branch -d old-branch.
git-branch You can use the prune subcommand of git-remote for cleaning obsolete remote-tracking branches. Alternatively, you can use the get-fetch command with the --prune option to remove any remote-tracking references that no longer exist on the remote. That's all about deleting remote-tracking branches in Git.
git branch -D -- --track
Did you try
git branch -D -- --track
? the "--
" is usually the convention for "what follows is not an option, whatever its name"
From "The Art of Unix Programming", section "Command-Line Options":
It is also conventional to recognize a double hyphen as a signal to stop option interpretation and treat all following arguments literally.
You will find that convention in other (not necessary Unix-related) CLI (Command Line Interface) like cleartool:
If a nonoption argument begins with a hyphen (
–
) character, you may need to precede it with a double-hyphen argument, to prevent it from being interpreted as an option:
cleartool rmtype -lbtype -- -temporary_label-
The P18 (a fast and flexible file preprocessor with macro processing capabilities and special support for internationalization) mentions that also and gives a good description of the general idea behind that convention:
All option arguments passed to the commands start with a single hyphen.
All option arguments (if any) must precede all non-option arguments.
The end of the option arguments may be signaled using a double hyphen, this is useful if a non-option argument starts with a hyphen. Terminating the list of option arguments with a double hyphen works for all commands, even those that don't take any option arguments.
The OptionParser tool written in ruby also lays it out quite plainly:*
Option Parsing Termination
It is convention that a double hyphen is a signal to stop option interpretation and to read the remaining statements on the command line literally. So, a command such as:
app -- -x -y -z
will not ‘see’ the three mode-flags. Instead, they will be treated as arguments to the application:
#args = ["-x", "-y", "-z"]
Note: sometimes, it takes three dashes and not two, especially when the CLI follows strictly the Gnu options styles:
The Gnu style command line options provide support for option words (or keywords), yet still maintain compatibility with the Unix style options.
The options in this style are sometimes referred to aslong_options
and the Unix style options asshort_options
.
The compatibility is maintained by preceding the long_options with two dashesSimilar to the Unix style double-hyphen ’
--
’, the Gnu style has a triple-hyphen ’---
’ to signal that option parsing be halted and to treat the remaining text as arguments (that is, read literally from the command line)
So... if ' --
' is not enough (it should be with Git commands), try ' ---
'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With