4

I have two branches: feature/x "feature/y"

I can checkout the first with no problems, but the one in quotes is giving me problems, with the error 'feature/y' did not match any files known to git.

ryan coughlan
  • 61
  • 1
  • 3
  • The answer for this question can help http://stackoverflow.com/questions/20374939/cant-checkout-git-branch-started-with-hyphen – OmarJ Apr 17 '16 at 14:03
  • You would do well to rename the problematic branch. Branch names that contains "exotic" characters can have [surprising consequences](http://stackoverflow.com/questions/32355540/complex-git-branch-name-broke-all-git-commands)... – jub0bs Apr 17 '16 at 14:06
  • 1
    @Jubobs I know this is not a useful comment for _this_ question but: thank you for the link! It was a real fun to read and you gave a great answer there. _Really_ surprising. :-) – PerlDuck Apr 17 '16 at 15:37
  • 1
    ... and to give a useful comment (hopefully): when you're done with checking out, rename the branch with `git branch -m '"feature/y"' feature/y` to get rid of the quotes. – PerlDuck Apr 17 '16 at 15:41

2 Answers2

12

You need to escape quotes so either of these should work

git checkout \"branch-name\"
git checkout '"branch-name"'
Hauleth
  • 22,873
  • 4
  • 61
  • 112
1

Another way to overcome this when there are single quotes used internally, you can surround the whole branch name in double quotes:

git checkout "branch-name-'with-single'-quotes-inside"

This is what the tool "GIT Extensions" does

Tim
  • 41
  • 7