3

Git allows you to create your own custom Git verbs, or aliases, using

git config [--global] alias.<alias-name> "<replacement-text>"

If you're not very familiar with Git commands, though, you may choose an alias name that corresponds to an existing Git verb; as an extremely dumb example, consider

git config --global alias.log show

No panic; according to git config --help:

To avoid confusion and troubles with script usage, aliases that hide existing Git commands are ignored.

Fine, but, in that case, Git won't tell you that your new alias will be ignored.

Therefore, I'm wondering whether there is a robust (and future-proof) way of checking whether my prospective alias name correspond to an existing Git verb, before actually defining the alias.

I was thinking of searching for <alias-name> in the output of git help --all, but the latter contains more than just a list of all Git verbs, so I'm not sure how robust such an approach would be...

Any idea?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • What's the exit code of the command when your alias was not created? Whether you check beforehand or check the exit code afterwards should not matter – knittl Aug 20 '14 at 21:24
  • @knittl Whether the name already corresponds to a Git verb or not, `git config --global alias. ` outputs nothing; therefore, there is no immediate way to tell whether the newly defined alias is "valid" or not. That's my problem. – jub0bs Aug 20 '14 at 21:24
  • yeah, just verified: the exit code is 0, and the alias is added to your `.gitconfig` (or `.git/config`), but only ignored when actually calling the alias. Maybe one should write a patch for Git to warn users? – knittl Aug 20 '14 at 21:27

1 Answers1

2

Sure, just run git help <command name>.

  • If the command exists, that will bring up the man page for the command in question
  • If the command is an existing alias, you'll get something along the lines of 'git l' is aliased to 'log'
  • If the command does not exist, you'll get an error message
Ajedi32
  • 45,670
  • 22
  • 127
  • 172