1

I'm not sure how it happened, but I somehow created a local git branch with a strange character in the branch name. When I type git branch, one of the branches listed is myBranch<U+0094>. I want to delete this branch, but when I go to delete the branch by copying the exact branch name, the following error happens:

$ git branch -d myBranch<U+0094>
bash: syntax error near unexpected token `newline'

I am using git bash for Windows. Any help would be appreciated. Thanks in advance!

Scott Greenfield
  • 2,788
  • 2
  • 22
  • 21
  • 1
    I assume it's literally a U+0094 character (see https://www.fileformat.info/info/unicode/char/0094/index.htm), in which case, type in `git branch -d $'myBranch\224bar'`. This uses the bash/sh `$'...'`` syntax, which accepts octal escapes. – torek Oct 23 '19 at 21:07
  • `error: branch 'myBranchbar' not found.` I'm not sure what the "bar" part is for. – Scott Greenfield Oct 30 '19 at 19:29
  • Oops, I was using a test branch in which I added `bar` to the end so I could try several variants with `\x` and `\u`. Leave out the `bar` part for your case! – torek Oct 30 '19 at 19:59

2 Answers2

2

Way 1:

Try using:

$ git branch -d -- myBranch<U+0094>

-- is here to inform getopt to stop parsing options.

Way 2:

  • If you're using PowerShell then the escape character is the " ` " (backward apostrophe/grave or backtick).
  • If you're using cmd.exe then the escape character is " ^ " (carat)
  • If you're using bash then the escape character is " \ " (backslash)

Use those escaping characters to escape special characters.

$ git branch -d myBranch\<U\+0094\>
Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
  • That is good info to know and might solve a similar issue for some people. Sadly, none of the three techniques worked for me. All of them said that the branch was not found. The same thing happened using Git GUI. I might just have to live with this annoying branch always being there. It's not really causing any problems, but I wanted to remove it. Thank you for trying. – Scott Greenfield Oct 28 '19 at 15:57
2

Go to .git/refs/heads/ and delete it there using rm. (Pro tip: use tab completion, so that your shell escapes the file name for you.)

kirelagin
  • 13,248
  • 2
  • 42
  • 57