-2

I'm trying to create an alias to init a repo, but it doesn't work and I'm not really sure why, this is the alias:

> git config --global alias.init-setinfo "git init && git config --global user.name \"myName\" && git config --global user.mail \"myMail@gmail.com\""

Calling it returns:

> expansion of alias 'init-setinfo' failed; 'git' is not a git command
Antonio P.
  • 48
  • 1
  • 6
  • 1
    There's little point in repeatedly setting/overwriting the *global* configuration on a per-repository basis. – chepner Nov 14 '21 at 19:39

1 Answers1

5

Git aliases automatically run git command.

That's why your alias expands to:

git git init && ...

Which explains the error you see.

One way to overcome this is to use the ! character in the alias definition which tells Git to run it as an external command:

git config --global alias.init-setinfo "!git init && ...

Référence documentation : https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases

(...) Git simply replaces the new command with whatever you alias it for. However, maybe you want to run an external command, rather than a Git subcommand. In that case, you start the command with a ! character.


Edit: see also Git Alias - Multiple Commands and Parameters

Gaël J
  • 11,274
  • 4
  • 17
  • 32