How to set complicated git config with quotes over ssh?

ghz 8months ago ⋅ 192 views
% ssh me@my-vm "git config --global alias.l 'log --graph --all --pretty=format:"%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset"'" 
zsh: no matches found: git config --global alias.l 'log --graph --all --pretty=format:%C(yellow)%h%C(cyan)%d%Creset 

I have no idea why this zsh error is happening.

Take on the other hand a simpler git config

% ssh me@my-vm "git config --global user.name 'First Last'"
Warning: Permanently added 'my-vm' (ED25519) to the list of known hosts.

which works flawlessly. Which leads me to believe that the issue isn't me trying to set git config but rather the complexity of the alias I'm trying to set, but I just don't know what the error is trying to tell me.

Answers

The error message you're encountering with Zsh, "zsh: no matches found," typically occurs when Zsh is attempting to expand patterns or wildcards, but it can't find any matches. In your case, it seems to be related to the formatting string you're passing to the git config command.

The issue lies with the double quotes around the --pretty=format: part of the command. Zsh interprets %C(yellow) and other % characters as special patterns, which it tries to expand. To prevent this behavior, you need to escape the % characters.

Here's how you can fix the command:

ssh me@my-vm "git config --global alias.l 'log --graph --all --pretty=format:\"%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset\"'"

By enclosing the entire format string within double quotes and escaping the % characters with backslashes (\), you prevent Zsh from attempting to interpret them as patterns.

This should resolve the error you're encountering, and the git config command should work as expected.