2

I already know how to make aliases, simple ones, complex ones and all is good except ...

I, now, would like to document my aliases so when I do

git my-super-alias --help

instead of just getting :

'my-super-alias' is aliased to '[super specific set of instructions]'

I would get :

'my-super-alias' is aliased to '[super specific set of instructions]' this serves [super specific purpose] which is useful for [super specific, yet not very obvious at first glance, reason]

Is there any way to have this in native git config ?

4
  • 1
    Does this answer your question? Adding 'git help' for alias commands? Commented Oct 12, 2020 at 13:28
  • It's one way of doing it but it is not very shareable nor is it readable from the cli (which was my implicit, yet untold, goal) moreover, if the official documentation changes, local documentation will go stale. But it's a neat trick though :) Commented Oct 12, 2020 at 13:32
  • 1
    What if you make your alias a full-fledged bash script that takes in --help as a parameter and then outputs the text and otherwise executes the alias? Commented Oct 12, 2020 at 14:35
  • Even though that is a bit heavy to do in practice that fits what I'd need to achieve on the user's side. But it's not very native and would impede readability of git's config itself :( So all in all I'd use it if my life depended on it but won't in practice (since my life is, thanks all almightinesses, pretty safe even without it). Clever idea though :) Commented Oct 12, 2020 at 15:54

2 Answers 2

3

You could make the start of the super-specific set of instructions be the help for them.

$ git config alias.testhelp '!# My super specific command does AMAZING THINGS!
date'
$ git testhelp
Fri Jan 29 11:29:52 AM PST 2021
$ git help testhelp
'testhelp ' is aliased to '!# My super specific command does AMAZING THINGS!
date'
$
Sign up to request clarification or add additional context in comments.

2 Comments

Very elegant and does a great deal of what I would expect yet still too much of a hack for me to consider it as THE solution. But very nice though :)
Yes but my question has always been less "How can I do it" than it's "Is there a really by the book way to do it". I know that's not satisfying on the answerer's end but I'm here to scratch an itch rather than to have something work :)
1

Even though that is a bit heavy to do in practice that fits what I'd need to achieve on the user's side. But it's not very native and would impede readability of git's config itself

There does not seem to be a native solution indeed.

I would have a wrapper for git itself:

  • detecting the --help parameter
  • checking if the command is an alias
  • calling my-super-alias-help

That way, you can define with git config a my-super-alias --help alias which is there to output the help text.

2 Comments

That's close to @mnestorov's solution in the comment and fits the visual user end result I'm after but it is too impractical for me to consider using it as a pedagogical device to show the simplicity of git :/ Might have to try to make this feature and pull-request it directly to git ^^
Agreed: per your specifications, this would require a patch to be sent to the Git mailing list indeed, in order to get that feature natively with Git itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.