Vsln
Vsln

Reputation: 73

Manage branch names containing invisible symbols

I have a local Git repository and some branches appear to exist, for example:

master
test
branch1
branch2
branch3

However, when I try to checkout or delete branch2, Git says that there is no such branch. In addition, I can create a new branch with the same name (branch2).

As far as I understand, I somehow managed to put invisible symbols in the branch names. When I do git branch, I can see branch2 but in reality it's branch2x, where x is some invisible symbol. Copying names from the screen helped with some branches, but not with all.

So my question is: Is there any way to manage branches without knowing their exact names. By position, by Id or any other way?

Upvotes: 1

Views: 651

Answers (2)

remcycles
remcycles

Reputation: 1523

You should be able to delete the branches using the tig command.

Use r to see all git references (branch names, tags, etc). From there you can UP/DOWN to highlight the branch in question and then ! to run git branch -D on the selected branch. Press h for more information on available tig commands.

I had the same problem after copy-and-pasting a branch name from a bug tracker webpage. In this case, my branch was prefixed with the Unicode <U+0096> START OF GUARDED AREA character. Because of the prefix, tab completion was no help. Once again, tig saved the day.

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520878

It is not possible to work with Git branches without using either a name or possibly a commit hash ID. If you don't know the names of your branches, I would suggest that you remedy that problem first before you proceed further. To get your local repository up to date with the latest information, try doing the following:

git fetch origin     # brings in all latest remote branches
git branch -a        # shows all local and remote branches

Whatever the git branch -a commands shows you should be the state of the art with regard to what branches are avaiable.

Upvotes: 1

Related Questions