git checkout gives zsh: no matches found:
Asked Answered
P

2

7

My colleague created a branch. I am trying to checkout to the branch.

git checkout hisName/branchNameWithAHash#Inside

The terminal returns

zsh: no matches found: hisName/branchNameWithAHash#Inside

If I do git branch -r, I can see the remote branch does exist:

origin/HEAD -> origin/master
  origin/hisName/branchNameWithAHash#Inside
  origin/master

Why am I getting no matches found?

Prefigure answered 30/8, 2021 at 7:15 Comment(5)
https://mcmap.net/q/1395723/-oh-my-zsh-hash-pound-symbol-bad-pattern-or-match-not-found Found in stackoverflow.com/search?q=%5Bzsh%5D+hash+symbolIridotomy
This is purely a zsh issue; it has nothing to do with Git.Stakhanovism
@Iridotomy : pattern removal can't explain this IMO, because we are not inside a ${....} parameter expansion, where the # indeed would have a special meaning.Marsupium
@RaphaelPinel : Can't reproduce your issue (with zsh 5.8). Do you get the same error when you do a echo instead of a git checkout? What is your zsh version?Marsupium
@Marsupium I also have zsh 5.8 and yes I am getting the same error 'no matches found' if I try echo echo stringwithhash# I get zsh: no matches found: stringwithhash#Prefigure
P
12

It turns out I need to put quotes around the branch name if it contains a special character like a hash sign #

with git checkout 'hisName/branchNameWithAHash#Inside' I get now:

Branch 'grzegorz/configureAWSAmplify_#PROAP-320' set up to track remote branch 'hisName/branchNameWithAHash#Inside' from 'origin'.
Switched to a new branch 'hisName/branchNameWithAHash#Inside'

I tested only 'single quotes' but I think "double quotes" should work as well.

Thanks @user1934428 to your comments and links @phd it seems to be an issue with my zsh config. Entering unsetopt EXTENDED_GLOB fixed the issue.

Now if I enter echo stringwithhash# I am getting stringwithhash# whereas before it was zsh: no matches found: stringwithhash#

Prefigure answered 30/8, 2021 at 7:15 Comment(5)
Of course quoting helps, but this does not explain, why in your concrete case quotes are needed. Depending on your settings, a # either introduces a comment or is just a normal character. # gets special treatment in globbing flags, but in this case , there should be parenthesis around it, such as (#q:.....). Even then you would have to turn on extended globbing explicitly.Marsupium
Ah, extended_glob was the culprit! On first reading of your posting, my first idea was indeed that you had enabled this, but then I read the man page and could not find an explanation, that extended globbing would affect the string you had in your example. Indeed, as I am rereading the zshexpn man page right now, I can not find it. Do you? If not, maybe you could ask a new question, asking what # is doing with extended globbing on the pattern you have.Marsupium
@Marsupium I am not an advanced zsh user, never opened the manual and I don't remember to have ever activated extended_glob, so it must have been there by default. Recently upgraded to Big Sur, don't know it it is related.Prefigure
'extended_glob' is off by default. You must have turned it on in one of the startup files. It could be possible that Apple has this setting in its system wide startup files, but I consider this highly unlikely. In any case, you can research this by running a zsh -xl and analyze the output, where this option is set. Maybe some other unwanted settings are done as well, so it would be useful to check for this reason too.Marsupium
BTW, I start to wonder whether this is maybe even a bug in zsh. Not even the man page mentions it, but also none of the tutuorial pages on extended zsh globbing which I found, seems to know this feature. BTW, a quite good overview of extended globs is here.Marsupium
T
1

I had a similar error while adding helm repo on my macOS like the following:

helm repo add chart-alias-name git+ssh://[email protected]/user/repo-name@chart/path?ref=ref-tag

> zsh: no matches found: git+ssh://[email protected]/user/repo-name@chart/path?ref=ref-tag

and I have fixed the problem by adding quotes around the full git URL like the following:

helm repo add chart-alias-name "git+ssh://[email protected]/user/repo-name@chart/path?ref=ref-tag"
Tare answered 17/12, 2021 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.