Scott Greenfield
Scott Greenfield

Reputation: 2828

How to delete local git branch with weird character in branch name

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!

Upvotes: 1

Views: 918

Answers (2)

kirelagin
kirelagin

Reputation: 13616

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

Upvotes: 3

Kamol Hasan
Kamol Hasan

Reputation: 13466

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\>

Upvotes: 2

Related Questions