It's likely that those branches are not named -h
, -merged
, and so on, but are instead named –h
, –merged
, and so on. It's still difficult to tell, but the second set of names are spelled with an en-dash as the first character, rather than with a hyphen as the first character. An en-dash is Unicode character U+2013.
The keyboard method for inputting such a character is up to the OS and/or keyboard and/or other software: there are few standards here. (On MacOS, the easiest way for me to type it is to hold down the option key and press the - key.)
To deal with it programmatically, you can use Python. For instance, in Python 3:
>>> import subprocess
>>> s = subprocess.check_output('git branch', shell=True).split(b'\n')
Printing the value in s
now produces the branch names as a list of byte-strings. In my case, after creating a branch named –merged
, one of them (s[5]
in my test repository here) is:
b' \xe2\x80\x93merged'
which shows the UTF-8 encoded sequence for en-dash:
>>> s[5].decode('utf8') == ' \N{en dash}merged'
True
>>> s[5].decode('utf8') == ' \u2013merged'
True
To delete it, I can invoke git branch -D
from Python again:
>>> subprocess.check_call('git branch -D \N{en dash}merged', shell=True)
Deleted branch –merged (was 4ede3d42df).
0
(Note that under Python 2.7, this is all a bit different as the built in string type is equivalent to the bytes
type, rather than the Python 2.7 unicode
type.)