2

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!

3
  • 1
    I assume it's literally a U+0094 character (see 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. Commented Oct 23, 2019 at 21:07
  • error: branch 'myBranchbar' not found. I'm not sure what the "bar" part is for. Commented Oct 30, 2019 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! Commented Oct 30, 2019 at 19:59

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure why, but tab completion worked for this where tab completion failed for git branch -d. Thank you!
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\> 

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.