2

I have a problem with deleting git branch. At first I was able to create it using 'git checkout -b ....'. But it seems to me, that I made a mistake while writing, hit something wrong, then backspace. It resulted in wrong name of this branch.

I was able to work on this branch, even push it to remote, but it makes weird behavior (cannot see branches in web interface).

git branch -r shows me

origin/master origin/rrseria_test_utility 

In web interface (bitbucket) I can see this branch in commits with following name

rrseriaÅl_test_utility 

Pleasse note that capital A is not just A, but A with circle above. Seems like utf-8 character 'U+00C5'.

When I try to remove it, then

git branch -d rrseria_test_utility error: branch 'rrseria_test_utility' not found. git checkout rrseria_test_utility error: pathspec 'rrseria_test_utility' did not match any file(s) known to git. 

Can you help me how to delete this branch ?

1
  • 2
    Can't you just type git branch -d rrseria and use TAB for auto completion? Or Copy/Paste the Å character? Or you can just delete the branches' directory in your .git/refs/heads/ directory . Commented May 16, 2018 at 8:17

1 Answer 1

2

You can use git branch --list rrseria* to list only the branches whose names start with rrseria. If there are more than one you can use a more specific pattern, using the * wildcard for the non-ASCII characters (rrseria*l_test_utility f.e.).

This command displays the name of the branch you want to delete.

If you are on Linux or macOS, you can use its output to create the Git command to delete that branch:

git branch -d $(git branch --list rrseria*) 

Or you can use the mouse to copy the branch name in the terminal window from the output of git branch --list and paste it (back into the terminal window) to create the git branch -d command.

Or you can use your favorite file manager to navigate in the .git/ref/heads directory and remove the file whose name matches the branch name (this is what git branch -d does in the background).

After that you have to push the deletion to the remote repositories:

git push origin --prune refs/heads/* 

If you have more than one remote then repeat the command above for each of them (put its name instead of origin).

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

2 Comments

You can use, as well, the techniques presented above (shell command line substitution, copy-paste, file operations) to rename the branch to the name you want, instead of deleting it. Just don't forget to run the git push --prune command after the rename or removal, to send the changes to the remotes too.
Hm... in my case git branch --list partialname* listing works and shows me the branch, but not deleting... also navigating to .git/refs/head doesn't show it...? Time to give up and remove the folder and check out the project from scratch? :P

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.