git checkout gives zsh: no matches found:

Viewed 4230

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?

2 Answers

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#

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

helm repo add chart-alias-name git+ssh://git@github.com/user/repo-name@chart/path?ref=ref-tag

> zsh: no matches found: git+ssh://git@github.com/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://git@github.com/user/repo-name@chart/path?ref=ref-tag"
Related