1

As seen is image, not sure how the branches -h -merged --help got created

Please click here for image showing all branches in local repo

How to delete unwanted branches[/accidentally created] branches?

Update text from git bash[Windows]

$ git branch -a * calc master –-help –h –merged remotes/origin/master

k_pruthvi
  • 11
  • 5
  • 4
    Please don't post images of text or code. Use the "copy" operation provided by your OS (Ctrl-C or Cmd-C) and paste the text as text into the question. – axiac Oct 31 '18 at 09:17
  • https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely – Bilal Saleem Oct 31 '18 at 09:18
  • Thanks to user:a_horse_with_no_name. @axiac as this is my first question , Stackoverflow did not allowed me to post an image inside description. – k_pruthvi Oct 31 '18 at 09:21
  • Use `git help branch` in your console or read the online documentation of [`git branch`](https://git-scm.com/docs/git-branch). All strings you put in the command line that are not valid options are interpreted as branch names or other reference names, depending on their position. – axiac Oct 31 '18 at 09:58
  • `-h` , `--help` are valid options only. But still branches are created. even when tried -merged got below response `$ git branch -D -merged` `error: did you mean `--merged` (with two dashes ?)` – k_pruthvi Oct 31 '18 at 10:55
  • for the above created branche `-h` `--help` `-merged`, I am unable to perform any of the operations like `checkout` or `delete` or `push` to remote. – k_pruthvi Oct 31 '18 at 12:48

1 Answers1

1

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

Nimantha
  • 6,405
  • 6
  • 28
  • 69
torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks torek for the explanation. I updated question with the text from git bash. – k_pruthvi Oct 31 '18 at 20:09
  • I understood somehow the command entered is `–` *U+2013 : EN DASH* instead of `-` *U+002D : HYPHEN-MINUS {hyphen or minus sign}*. Thanks for your help. I am able to access those branches with `–` character. – k_pruthvi Oct 31 '18 at 20:14
  • Most likely you copied text from a webpage to learn git, and it used the wrong symbol. – Lasse V. Karlsen Oct 31 '18 at 20:15