3

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()?

Pr.Dumbledor
  • 636
  • 1
  • 11
  • 29

1 Answers1

2

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)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250