How to delete a branch with non-UTF-8 characters in the branch name in Bitbucket Server and Data Center

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Branches with names containing non-UTF-8 or special characters cannot be deleted from the Bitbucket UI or with the git push <remote> --delete <branch> command.

Solution

Here are the procedures to follow to remove branches with non-UTF-8 or special characters:

Solution 1

  • Get the repository location on disk for the affected repo. In the Bitbucket UI, go the Repository Settings > Repository details and look for the "Location on disk" value.

  • On the server, go to the location on disk

  • Run the following commands to search for the specific branch to delete and convert it to Hex values:

    1 git branch -a | grep <pattern_to_match_the_branch> | hexdump -C

    This will return Hex values.

    For example: branch is: "test�"

    To search and convert it to Hex:

    1 git branch -a | grep "test" | hexdump -C

    This will return:

    1 00000000 20 20 74 65 73 74 a1 34 0a | test...|
  • Analyze the output In the sample above:

    "20 20" are for 2 spaces "74 65 73 74" are the Hex values for "test" "a1 34" are for the character "0a" is for the line feed character

  • Use the relevant Hex values for the Git command to delete the branch.

    For the sample above, to delete the branch from the remote:

    1 git push origin --delete $'test\xa1\x34'

Solution 2

These procedures will modify refs on the server. Make sure to create a backup of the repository before proceeding.

The steps are preceded with either "local" or "server" to indicate where the steps should be performed:

  • local - perform on a local copy of the repo

  • server - perform on the server

  1. local: Pull or clone the repository from the remote to ensure that the ref objects and commit hashes on the local copy are up to date

  2. server: Identify the location on disk for the affected repo. In the Bitbucket UI, go the Repository Settings > Repository details and look for the "Location on disk" value.

  3. server: Create a backup copy of the repo

  4. server: Go to the location on disk and check if the bad ref is in the refs/head/ folder as a file (i.e. refs/head/<refname>) or inside the /packed-refs file.

  5. server:If the ref is inside the/packed-refsfile, we will need to shut down Bitbucket before making any changes.

    While shutdown, edit the /packed-refsfile and remove the bad line.

  6. server: If the ref is in the refs/head/ folder as a file (i.e. refs/head/<refname>), delete the file

    At this point, the refs are now removed from the server.

  7. local:Open the .git folder in the local repository

  8. local:Check if the bad ref is in therefs/head/folder as a file (i.e. refs/head/<refname>) or inside the/packed-refsfile

  9. local:If the ref is inside the/packed-refsfile delete the line containing the bad ref

  10. local: If the ref is in the refs/head/ folder as a file (i.e. refs/head/<refname>), delete the file

  11. local:Open the config file and find the bad branch name and delete the section with the bad branch.

  12. local:Create a new branch on the same commit hash that the bad ref was pointing to.

    For example:

    1 2 git checkout <commit hash> git branch newname
  13. local: Push the branch to the remote.

The remote and local copy should now have the correct new refs. However, old clones/other users may have the old bad ref.

Please let others know about the change and share the procedures performed on the local copy of the repo.

Updated on March 20, 2025

Still need help?

The Atlassian Community is here for you.