When I try to create an alias
[alias]
my-alias = submodule foreach 'git foo ; git bar'
Git (version 1.7.1) spews the error
user@host:/path/repo.git$ git my-alias
error: unclosed quote
fatal: Bad alias.my-alias string
It appears that .gitconfig
uses weird parsing rules, so that ;
is treated as starting a line comment, even inside of a quote.
How do I specify this alias?
For complete flexibility, define and call a function:
This alias can be called as
git conf
,git conf --local
orgit conf --global
, and the extra options are inserted in the appropriate place.Not sure if this is related to the semicolon, but here goes - here is another test for git alias, using
bash
:test:
Any other form of escape gives me either plain old "fatal: bad config file line", or “Unterminated quoted string” or “unexpected EOF” (see also shell - Calling bash from sh (dash) with commands read from args, and "Unterminated quoted string"/"unexpected EOF" - Unix & Linux Stack Exchange)
Also for multiline:
... and add
\n\
to the end of line, if you want to use inlinebash
comments (#
):I have
Just wrap the command into double-quotes, e.g.:
To include semicolon for
find
, double-escape it, like:Same with your command:
For troubleshooting, prefix your command with
GIT_TRACE=1
to debug your alias, e.g.You need to use doublequotes (
"
) rather than singlequotes ('
).Wrap the entire alias command in double quotes:
The double quotes cause the
.gitconfig
parser to pass the semicolon. The single quotes are still needed to delimit the argument tosubmodule foreach
; without them, it gets parsed asso that
git bar
only gets executed once, at the end.