1

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?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Vsln
  • 73
  • 6
  • 2
    write `git branch` in the console and it will list all branches in your project. https://git-scm.com/docs/git-branch – Kristiyan D Kovachev Jan 25 '18 at 10:32
  • You could try the solutions for renaming the branch as discussed in [my answer here](https://stackoverflow.com/a/15372154/216074) or [here](https://stackoverflow.com/a/20970918/216074). I’d also suggest you to use a console that can handle Unicode properly and then copy the name exactly from the `git branch` output. – poke Jan 25 '18 at 11:12
  • 2
    You could try to let autocomplete help you. Type `git branch -m branch2` and then a normal name without special symbols. – mkrieger1 Jan 25 '18 at 11:16
  • My favorite trick is to use `git branch` or `git for-each-ref` but pipe the output through a command that visually-expands all non-printing characters. The "right" command (opinion warning) for this is `vis` if you have it, but it's BSD-specific. – torek Jan 25 '18 at 16:25

2 Answers2

1

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

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.

remcycles
  • 1,246
  • 13
  • 14