Unable to delete git remote branch with a special character

Viewed 585

Please, before mark this question as duplicated, read carefully.

If you list branches, it appears like this:

$git branch -a
  remotes/origin/feat/verify-<C3>email

The branch name is:

origin/feat/verify-√email

If you try to access the branch url from Github Dashboard:

The github page broke into a HTTP error 400

If you try to delete the branch:

$ git push origin --delete feat/verify-√email
error: unable to delete 'feat/verify-√email': remote ref does not exist
error: failed to push some refs to 'https://mataide@github.com/mataide/proak-website.git'

Delete by pattern:

git branch -d -r $(git branch --list origin/feat/ve* -r)
error: cannot lock ref 'refs/remotes/origin/feat/verify-?email': Unable to create '/Users/marcus/Documents/Workspace/proak-website/.git/refs/remotes/origin/feat/verify-?email.lock': Illegal byte sequence
error: Error deleting remote-tracking branch 'origin/feat/verify-?email'

Same error if you try by the name: feat/verify-email. Also doent work if you try to delete by tools like Sourcetree.

I just want to delete the branch, any help?

1 Answers

The √ character that I cut and pasted from your posting is a Unicode character for square root: U+221A—see also https://en.wikipedia.org/wiki/Radical_symbol. The one actually in the other Git appears to be a code-byte-C3 in some non-Unicode character set. You'll need to get the other Git to remove that somehow.

The git push --delete is a good idea, but you have to send the exact byte sequence to that other Git. It's not clear to me how to do that from whatever terminal session you're using. If you're on MacOS, you could edit up a shell script file that has the right byte sequence: just run git branch -r > /tmp/script, open the file in a suitable editor (e.g., vim), delete all the irrelevant lines, and insert git push origin --delete in front of the remaining one with the bad name. Then run the resulting script, e.g., sh /tmp/script. With no human hands (or editor) touching the bytes on the line, the original byte code sequence should remain in place.

Using git branch -d -r will, even if it works, not really help, as the name will keep coming back as long as it exists in the other Git. However, once you've gotten rid of the bad name on the other Git—which might require outside help, e.g., from the GitHub folks—a git fetch --prune may not be able to discard the remote-tracking name in your own repository either. (Try it first though.)

Given that your OS won't let you create the lock file for that name, you'll need to manually remove the right entry, which will be a line in your .git/packed-refs file. Use a text-file-only editor (not a rich-text editor) that can handle newline-terminated lines (not CRLF) and delete the line.

Related