1

Is it possible to list the options of a Git command from the command line?

I am aware of git help <command> and git <command> --help, which provide the full documentation of a command with the complete list of its options. However, they redirect the user to a web page, leaving the command line.

Instead, I would like to know if there is a way to list the options of a command within the command line. I don't need the full documentation; just a list of the possible options will do.

5
  • 2
    There is of course git -h and git <command> -h which outputs a shorter version of the help in the terminal. Commented Sep 30, 2024 at 17:30
  • Thank you for your input @joanis! I'll include it in the answer. Commented Sep 30, 2024 at 17:31
  • “However, they redirect the user to a web page, leaving the command line.”—Not on all installations. Are you using git-bash(1)? I just get the man page. Commented Sep 30, 2024 at 17:50
  • @Guildenstern yes, I'm using Git bash for Windows Commented Sep 30, 2024 at 18:00
  • 1
    Force the use of a man page (not a webpage) and go to Synopsis: PAGER='less -p ^SYNOPSIS' git help -m add. stolen from Hopefully then all the options are documented in the Synopsis (might not be true). Commented Sep 30, 2024 at 18:00

2 Answers 2

2

(piggybacking on @Guildenstern comment):

git help help indicates:

-m, --man

Display manual page for the command in the man format. This option may be used to override a value set in the help.format configuration variable.

By default the man program will be used to display the manual page, but the man.viewer configuration variable may be used to choose other display programs (see below).

You can try: git config --global help.format man.

See also the "Configuration Variables" section.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer. This configuration looks easier. However, when I type git commit --help after setting up help.format man, I receive warning: failed to exec 'man': No such file or directory.
Yeah, just noticed man.<tool>.path. Thank you a lot!
[reworded] check the "Configuration Variables" section: there is a way to specify the path to a command (if you have man actually installed somewhere ?) or a wrapper/alias (man.viewer = <tool> + man.<tool>.path or man.<tool>.cmd)
2

To have the full option list of a Git command, you can type git <command> -h. This will prompt Git to print:

  • The command's syntax.
  • The full command's option list.
  • A brief description of each option.

For example:

git init -h

usage: git init [-q | --quiet] [--bare] [--template=<template-directory>]
                [--separate-git-dir <git-dir>] [--object-format=<format>]
                [--ref-format=<format>]
                [-b <branch-name> | --initial-branch=<branch-name>]
                [--shared[=<permissions>]] [<directory>]

    --[no-]template <template-directory> directory from which templates will be used
    --[no-]bare                          create a bare repository
    --shared[=<permissions>]             specify that the git repository is to be shared amongst several users
    -q, --[no-]quiet                     be quiet
    --[no-]separate-git-dir <gitdir>     separate git dir from working tree
    -b, --[no-]initial-branch <name>     override the name of the initial branch
    --[no-]object-format <hash>          specify the hash algorithm to use
    --[no-]ref-format <format>           specify the reference format to use

Alternatively, you can enter a command followed by a double dash, and then type the TAB key twice. Note that this approach only shows the options preceded by a double dash. Single dash options are excluded.

For example:

git init --<TAB><TAB>

--bare               --object-format=     --shared
--initial-branch=    --quiet              --template=
--no-...             --ref-format=
--no-template        --separate-git-dir=

Credits: thanks @joanis for your comment.

1 Comment

I tried to find a way to do this completion programmatically. I found this and got stuck on Command '_git' not found, did you mean:.

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.