Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't checkout git branch started with hyphen (-)

Tags:

git

I have cloned a git repository.
This repository has a remote branch something like -feature-abc.
When I type git checkout -feature-abc, I get:

error: unknown switch `e'

Any idea how to checkout this branch?

like image 332
chanchal118 Avatar asked Dec 04 '13 12:12

chanchal118


1 Answers

Try using this syntax:

git checkout -- -feature-abc

The double hyphen syntax should help git separate the command options from the actual branch name parameter, as I explained before in "Deleting a badly named git branch".


If that doesn't work, you can follow the recipe suggested in "How do I rename a local Git branch?"

Go into your working copy's .git/refs/heads, find the filename "-dumb-name", get the hash of the branch. Then this will check it out, make a new branch with a sane name, and delete the old one.

  • Go into your working copy's .git/refs/heads,
  • find the file named "-feature-abc",
  • get the hash of the branch (cat the file).
  • Then check it out, make a new branch with a sane name, and delete the old one.
git checkout {hash}
git checkout -b brilliant-name
git branch -d -- -dumb-name
like image 164
VonC Avatar answered Sep 24 '22 06:09

VonC