4

Git has this feature, where you can place any executable named git-foo on $PATH and then call it as git foo <args>, like a built-in subcommand (or is it more of a side-effect of how Git implemented subcommands in the early days?).

I learned this probably 15 years ago and now told someone about this who didn't know it already. I'd like to point them to some documentation explaining it in a bit more detail (e.g. the variables that are placed in the environment) by git.

Where is this behavior documented in the official documentation (or e.g. in a mail thread by the developers)?

Feuermurmel
  • 9,490
  • 10
  • 60
  • 90
  • 1
    It's probably related to how git handles aliasing? Maybe also related to things like `man git-diff`? – evolutionxbox Oct 12 '22 at 09:35
  • Yes, I think the convention of putting the man page under `git-diff` began when you could still call `git diff` as `git-diff` (which doesn't work anymore today). – Feuermurmel Oct 12 '22 at 09:41
  • 3
    it is at least mentioned [here](https://git-scm.com/docs/git#Documentation/git.txt---list-cmdsgroupgroup82308203) ... :D – LeGEC Oct 12 '22 at 09:47
  • 1
    Yeah, what @LeGEC linked is the only place that I found in the official docs which even acknowledges that this works under `list-cmds` it mentions "others (all other commands in `$PATH` that have git- prefix)" – Joachim Sauer Oct 12 '22 at 09:49
  • 2
    It mentions "the non-dashed form of Git commands" in https://www.git-scm.com/docs/gitcli. But it does not give more details on "dashed form of Git commands". And `git-foo` like `git-log` is not valid now. – ElpieKay Oct 12 '22 at 09:53
  • @LeGEC Why not post that as an answer? – Guildenstern May 07 '23 at 12:04
  • @Guildenstern I was hoping that someone would point to some more assertive source -- not a side note to an option marked "experimental" :) – LeGEC May 07 '23 at 14:01

1 Answers1

2

The only place I know of in the documentation is here (git help git, --list-cmds option, emphasis mine) :

--list-cmds=group[,group…]

List commands by group.
This is an internal/experimental option and may change or be removed in the future. Supported groups are: builtins, parseopt (builtin commands that use parse-options), main (all commands in libexec directory), others (all other commands in $PATH that have git- prefix), list-<category> (see categories in command-list.txt), nohelpers (exclude helper commands), alias and config (retrieve command list from config variable completion.commands)

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Yes, it _kind of_ hints at the fact that anything on `$PATH` called `git-` is considered a "git command" and thus can maybe be called as `git foo`, but it doesn't say it out loud. :D I think this comes closest to answering my original question. Thank you for the answer! – Feuermurmel May 07 '23 at 18:36