Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I checkout a branch name having special character '-'?

Tags:

git

I created a git branch name -new-br:

git checkout -b -new-br.

I switched back to parent branch.

Now I am unable to checkout -new-br.

git checkout -new-br.
getting error:
error: unknown switch `n'
usage: git checkout [options] <branch>
   or: git checkout [options] [<branch>] -- <file>...

How can I check this branch out?

like image 841
thunga Avatar asked Jan 07 '14 11:01

thunga


1 Answers

Many Unix commands accept -- to mean "no more switches" and further arguments aren't then parsed as switches. See "What does “--” (double-dash) mean?" on this adjacent site.

So...

git checkout -- -new-br

...would probably suffice.

However... which version of Git are you using to create such a branch? Git version 1.8.4 tells me:

git checkout -b -new-br
fatal: '-new-br' is not a valid branch name.

Trying it another way...

git branch -- -new-br
fatal: '-new-br' is not a valid branch name

I suggest that you check the names of all your branches with:

git branch --list --all

Reference:

  • git-branch(1) Manual Page
like image 117
Johnsyweb Avatar answered Oct 01 '22 01:10

Johnsyweb