zappee
zappee

Reputation: 22668

git delete branch with name contains special chars

Could you please help me? I have created a git branch with wrong name and I am not able to delete it because the name contains some crazy characters. I copied and pasted the name and unfortunately at the end of the text there were some unseen characters.

>git ls-remote
5fe385e6bd6b49f87f470e0a5b22b67042b179ad        HEAD
dbdadb9d8c630782144028d50f01b84a6ff61612        refs/heads/feature/ABC-495-test1
6660c993b5a5e35922a1f7b3f2bb75c6b0996f6e        refs/heads/feature/ABC-496
dbdadb9d8c630782144028d50f01b84a6ff61612        refs/heads/feature/ABC-501-mapping
dbdadb9d8c630782144028d50f01b84a6ff61612        refs/heads/feature/ABC-501-mapping?
5fe385e6bd6b49f87f470e0a5b22b67042b179ad        refs/heads/master

I would like to delete the branch with the name of "refs/heads/feature/ABC-501-mapping?" but i do not know how :(

Thanks

Upvotes: 5

Views: 4112

Answers (4)

Stéphane Bertusi
Stéphane Bertusi

Reputation: 21

My special branch name : 60954_Plante_transient_60_pack_raf_odessa_r992�_fin

My command to suppress the branch :

git branch --all | grep 60954_Plante_transie | xargs git branch -D

Deleted branch 60954_Plante_transient_60_pack_raf_odessa_r992�_fin (was d6bfec3).

Upvotes: 1

gabriel magnuson
gabriel magnuson

Reputation: 1

Similar option to Yair.

I had luck copying the whole branch name (remote prefix and all) out of a git bash window via a git branch --all command (note: for me at least I was not seeing the special character in bash), then pasting it into a delete, and then deleting the remote prefix from branch name (from the left so as not to delete any special characters if they happen to be first).

You can optionally use a grep to narrow down your branch command

git branch --all | grep <string to match branch>
git push origin --delete <copy pasted branch with deleted remote prefix>

Upvotes: 0

Yair Galler
Yair Galler

Reputation: 121

When I couldn't enter the special charater, I found a way to delete a remote branch by piping the name of the branch into the delete command:

git ls-remote|grep -i <partial name of the branch>|cut -f3 -d/|tail -1|xargs git push origin -d

Upvotes: 2

Sajib Khan
Sajib Khan

Reputation: 24156

Try this:

$ git checkout master
$ git branch -D "feature\/ABC-501-mapping\?"         # delete local branch
$ git push origin :"feature\/ABC-501-mapping\?"      # delete remote branch

Or,

$ cd .git/refs/heads
$ rm "feature/ABC-501-mapping?"

Upvotes: 8

Related Questions