MYK MYK - 4 years ago 125
Git Question

Branch name starting with '-' in git

I am moving from svn to git using git-svn, and some of my branches names started with '-'. Now with help form this question and this migration documentation I am able to pass parameters starting with '-'. but on creating branch git returns an error stating:


fatal: '-CLOSED-mybranch' is not a valid branch name.


I am using gitlab. The command that I am running to create branches is:

git for-each-ref refs/remotes | cut -d / -f 3- | grep -v @ | while read branchname; do git branch -- "$branchname" --"refs/remotes/$branchname"; git branch -r -d -- "$branchname"; done


This articles explains legal branch names and I think my branch name is Legal. Can anyone tell me where the problem could be?

PS: branch name not starting with '-' are successfully imported.

Answer Source

It doesn't seem you can create a branch which name starts with a dash:

$ git branch "-test"
error: unknown switch `e'

It apparently thinks that I'm trying to set the git branch option -t, and then gives an error on the following e.

It also doesn't work with this command:

$ git checkout -b "-test"
fatal: '-test' is not a valid branch name.

In this case it actually really says that -test is not a valid branch name. So it's probably best if you change your branch names so that they won't start with a dash.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download