TExcelTAD
Home › Git › Git Help

Git Help

Git has well over a hundred commands and thousands of options. Nobody remembers them all; experienced users simply know how to look things up quickly. Git ships with three levels of built-in help.

Command Shows Typical use
git <command> -h a short usage summary in the terminal "what was that option called?"
git help <command> or git <command> --help the full manual page reading about a command in depth
git help -a, git help -g lists of all commands and of concept guides discovering what exists

Quick option summary: -h

-h prints a compact list of options and returns to the prompt. It is the fastest way to check a flag:

bash · try it yourself
git stash -h | head -12
usage: git stash list [<log-options>]
   or: git stash show [-u | --include-untracked | --only-untracked] [<diff-options>] [<stash>]
   or: git stash drop [-q | --quiet] [<stash>]
   or: git stash pop [--index] [-q | --quiet] [<stash>]
   or: git stash apply [--index] [-q | --quiet] [<stash>]
   or: git stash branch <branchname> [<stash>]
   or: git stash [push] [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet]
                 [-u | --include-untracked] [-a | --all] [(-m | --message) <message>]
                 [--pathspec-from-file=<file> [--pathspec-file-nul]]
                 [--] [<pathspec>...]
   or: git stash save [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet]
                 [-u | --include-untracked] [-a | --all] [<message>]

The square brackets mark optional parts and | separates alternatives. Filtering the summary with grep is a quick way to find one flag. Here are the -a, -m and -q options of git commit:

bash · try it yourself
git commit -h | grep -E "^ +-[amq],"
    -q, --[no-]quiet      suppress summary after successful commit
    -m, --[no-]message <message>
    -a, --[no-]all        commit all changed files

The full manual

git help commit (identical to git commit --help) opens the complete manual page, with a description, every option and examples. On Linux and macOS it uses man; on Windows it opens the HTML version in your browser. Inside man, use /word to search, n for the next match and q to quit.

bash
git help commit
git commit --help
git help -w commit     # open the HTML version in a browser

Note: git commit -h (one dash) and git commit --help (two dashes) look similar but do different things: the first prints the short summary in the terminal, the second opens the full manual page.

Discovering commands and guides

git help -a lists every available command, grouped by purpose. git help -g lists the concept guides, such as gitignore, gitglossary and gitworkflows, which you open with git help <guide>:

bash · try it yourself
git help -a | sed -n '1,12p'
echo "..."
git help -g | head -8
See 'git help <command>' to read about a specific subcommand

Main Porcelain Commands
   add                     Add file contents to the index
   am                      Apply a series of patches from a mailbox
   archive                 Create an archive of files from a named tree
   backfill                Download missing objects in a partial clone
   bisect                  Use binary search to find the commit that introduced a bug
   branch                  List, create, or delete branches
   bundle                  Move objects and refs by archive
   checkout                Switch branches or restore working tree files
   cherry-pick             Apply the changes introduced by some existing commits
...
The Git concept guides are:
   core-tutorial    A Git core tutorial for developers
   credentials      Providing usernames and passwords to Git
   cvs-migration    Git for CVS users
   diffcore         Tweaking diff output
   everyday         A useful minimum set of commands for Everyday Git
   faq              Frequently asked questions about using Git
   glossary         A Git Glossary

Typos and suggestions

When you mistype a command, Git suggests the closest matches:

bash · try it yourself
git stats
echo "exit status: $?"
git: 'stats' is not a git command. See 'git --help'.

The most similar command is
	status
exit status: 1

You can let Git run the suggestion automatically with git config --global help.autocorrect prompt (asks first) or a number of tenths of a second to wait before running it.

Online resources

  • The official reference at git-scm.com/docs has every manual page.
  • The free book Pro Git (git-scm.com/book) explains concepts in depth.
  • git help gitglossary (or this course's glossary) defines the jargon.

Test yourself

Which command prints a short option summary for git log directly in the terminal?

  1. git log --help
  2. git log -h
  3. git help -g log
  4. man git

Which command lists Git's concept guides (like gitignore and gitworkflows)?

  1. git help -a
  2. git help -g
  3. git guides
  4. git log --guides