Pr.Dumbledor
Pr.Dumbledor

Reputation: 646

Can't add git alias when using shell function

I'm trying to add the following alias using shell function

scommit = "!f() { git submodule foreach -q --recursive 'git commit -a || :' ; git commit -am \" Update submodule \";}; f"

But when I run it in Git bash (on Windows)

git config --local alias.scommit "!f() { git submodule foreach -q --recursive 'git commit -a || :' ; git commit -am "" Update submodule "";}; f"

I got output

git config --local alias.scommit "fit fetch upstream() { git submodule foreach -q --recursive 'git commit -a || :' ; git commit -am "" Update submodule "";}; f"

and of course it doesn't work because

Expansion of alias 'scommit' failed; 'fit' is not a git command

Also I tried to run it in PowerShell but it shows usage: git config [] …

When I add it to .git/config manually then it works.

How can I add this alias using git bash/ command line / PowerShell ? Why does it transforms to fit fetch upstream()?

Upvotes: 3

Views: 122

Answers (1)

VonC
VonC

Reputation: 1323125

I just tested, on Windows 10, with Git 2.18:

git config --local alias.scommit '!f() { git submodule foreach -q --recursive "git commit -a" || : ; git commit -am "Update submodule";}; f'

The idea is to inverse the quotes: strong quotes (') at the outside of the alias, weak quotes (") inside.

That avoids for ! to be interpreted as extended a command from history (as you can see here) (although set +o histexpand before the git config command could have helped)

Upvotes: 2

Related Questions