git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Support "git cmd --help" syntax

From
Linus Torvalds <torvalds@osdl.org>
Date
Apr 15, 2006, 18:13 UTC
Message-ID
<Pine.LNX.4.64.0604151054380.3701@g5.osdl.org>

The "--help" argument is special, in that it is (along with "--version") in that is taken by the "git" program itself rather than the sub-command, and thus we've had the syntax "git --help cmd".

However, as anybody who has ever used CVS or some similar devil-spawn program, it's confusing as h*ll when options before the sub-command act differently from options after the sub-command, so this quick hack just makes it acceptable to do "git cmd --help" instead, and get the exact same result.

It may be hacky, but it's simple and does the trick.

Of course, this does not help if you use one of the non-builtin commands without using the "git" helper. Ie you won't be getting a man-page just because you do "git-rev-list --help". Don't expect us to be quite _that_ helpful.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/git.c b/git.c
index 78ed403..13c6d51 100644
--- a/git.c
+++ b/git.c
@@ -411,6 +411,12 @@ static void handle_internal_command(int 
 	};
 	int i;
 
+	/* Turn "git cmd --help" into "git help cmd" */
+	if (argc > 1 && !strcmp(argv[1], "--help")) {
+		argv[1] = argv[0];
+		argv[0] = cmd = "help";
+	}
+
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
 		struct cmd_struct *p = commands+i;
 		if (strcmp(p->cmd, cmd))
Next: Junio C Hamano
Message 1 of 5 in “Support "git cmd --help" syntax”
  1. Linus TorvaldsApr 15, 2006
  2. Junio C HamanoApr 15, 2006
  3. Linus TorvaldsApr 15, 2006
  4. Junio C HamanoApr 16, 2006
  5. Jakub NarebskiApr 19, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.