Sub topic 10
Finding help in Git
Git has hundreds of options, and nobody remembers all of them. Git ships with its own reference material, and you can reach it from the terminal without a network connection. This chapter covers the built-in help system: the short and long forms of help, how to read the manual pages, how to find commands and concept guides, and how to make the help open the way you prefer.
Prerequisites and goals
This chapter assumes you have:
- Git installed and working.
git --versionshould print a version number. - A terminal where you can run commands.
- A rough idea of what a commit and a repository are, from the earlier chapters.
By the end you should be able to:
- Choose between
git help <command>,git <command> --help, andgit <command> -h. - Read a command synopsis and tell required parts from optional ones.
- List all commands and all concept guides.
- Change how help is displayed (terminal pager, web browser).
- Explain what Git's "did you mean" suggestion does and how to configure it.
The three ways to ask for help
Git offers three equivalent-looking entry points. They differ in what they print and what they need.
| Command | What you get | Needs a man page viewer |
|---|---|---|
| `git help <command>` | The full manual page | Depends on the configured format |
| `git <command> --help` | The full manual page, same as above | Depends on the configured format |
| `git <command> -h` | A short usage summary in the terminal | No |
The first two are the same operation. When Git sees --help after a command name, it rewrites the call to git help <command>. The sample from the Topic Spine shows both:
git help commit
git commit --helpShort help with -h
The -h option prints a compact usage message and exits. It is the fastest way to recall an option name:
git commit -hThe output starts like this (the exact options vary by Git version):
usage: git commit [-v | --quiet] [-a | --interactive | --patch] [-s] [-n] [-m <msg> | -F <file>]
or: git commit [<options>] [--] <pathspec>...
...Two details are worth knowing:
-hworks for most built-in commands, even on systems with no manual pages installed.- Git exits with status 129 after printing usage this way. This matters in scripts that use
set -e, because a stray-hwill stop the script.
git commit -h > /dev/null
echo $?This prints 129 on a typical Linux or macOS shell.
Full help with help and --help
The manual page has everything: purpose, every option, examples, configuration variables, and related commands. Use it when the short summary is not enough.
git help statusYou can also ask for the page about Git itself, which lists the main commands and the guides:
git help gitReading a manual page
Most Git manual pages follow the same layout. Once you know it, you can jump straight to the part you need.
| Section | What it tells you |
|---|---|
| NAME | The command and a one-line purpose |
| SYNOPSIS | The accepted forms of the command |
| DESCRIPTION | What the command does and how it works |
| OPTIONS | Each flag, with its long and short forms |
| EXAMPLES | Short worked uses (not on every page) |
| CONFIGURATION | Config variables that change the behavior |
| SEE ALSO | Related commands and guides |
| GIT | A footer naming the Git suite |
Navigating in the pager
On Linux and macOS, manual pages open in a pager, usually less. These keys work in it:
| Key | Action |
|---|---|
| Space or `f` | Next page |
| `b` | Previous page |
| `/text` then Enter | Search forward for `text` |
| `n` / `N` | Next / previous match |
| `g` / `G` | Top / bottom |
| `q` | Quit |
Searching is the habit that saves the most time. To find what a flag does, open the page, type /--amend, and press Enter.
Reading the synopsis
The SYNOPSIS section uses a compact notation. This is the first line from git help commit, abbreviated:
git commit [-a | --interactive | --patch] [-s] [-v] [-m <msg>] [--] [<pathspec>...]| Notation | Meaning | Column |
|---|---|---|
| `[ ]` | Optional | |
| `< >` | A placeholder you replace with a value | |
| `\ | ` | Choose one of the alternatives |
| `...` | The item may repeat | |
| `--` | Separator: everything after it is a path, not an option |
So -m <msg> means "the flag -m followed by your message text", and [<pathspec>...] means "zero or more paths".
The standalone -- is a common source of confusion. If a file is named -v, Git would read it as an option. Writing git commit -- -v tells Git that what follows is a path.
Discovering commands and guides
Sometimes you don't know the command name. Git can list what exists.
Listing commands
git help -aThe -a (or --all) option prints every available Git command, grouped by purpose. The list is long, so filter it:
git help -a | grep -i branchWithout -a, git help prints only the commonly used commands:
git helpListing concept guides
Not all documentation is about a command. Git also ships guides on ideas and conventions. List them with -g (or --guides):
git help -gGuides have names that start with git. You can open one by its short name or its full name:
git help glossary
git help gitglossaryBoth open the same page. Useful guides at this stage:
| Guide | Open with | Covers |
|---|---|---|
| gitglossary | `git help glossary` | Definitions of Git terms such as index, ref, HEAD |
| gittutorial | `git help tutorial` | A short hands-on introduction |
| giteveryday | `git help everyday` | A useful minimum set of commands |
| gitcli | `git help cli` | Conventions for options and arguments |
| gitrevisions | `git help revisions` | Ways to name commits, such as `HEAD~2` |
When a manual page uses a word you don't recognize, check the glossary first. It is short and is written to be searched.
Listing configuration variables
Recent Git versions can list every configuration variable the help knows about:
git help -cThis is useful after the configuration chapter. If you want to know what a variable such as init.defaultBranch does, the same list points you to the pages that describe it. The full list is also in git help config.
Choosing how help is displayed
The git help command can open documentation in several formats. You choose per call or set a default.
| Option | Format | Opens in |
|---|---|---|
| `-m` or `--man` | Manual page | A terminal pager via `man` |
| `-w` or `--web` | HTML | Your web browser |
| `-i` or `--info` | Info page | The `info` viewer |
git help -w commitTo make a format the default, set help.format:
git config --global help.format webValid values are man, info, and web (html is accepted as a synonym). Reset it by removing the setting:
git config --global --unset help.formatPlatform differences
Where help opens by default depends on how Git was installed:
- On Linux, the
gitpackage installs manual pages in most distributions, but some minimal installs and containers leave them out. Ifmanreports "No manual entry", install theman-dbpackage (on Debian or Ubuntu) and make sure the Git documentation is present. - On macOS, Git from Homebrew installs man pages. The Apple-supplied Git from the command line tools also has them.
- On Windows, Git for Windows does not include
man. Itsgit helpopens the HTML version in your default browser.
You can find the folder that holds the local HTML documentation:
git --html-pathThe files are plain HTML, so they work offline.
Online reference
The same manual is published at https://git-scm.com/docs. The online version tracks the latest release. Your local pages match the Git version you installed, which is the one you should trust when behavior seems different. Check with git --version.
Aliases and help
An alias is a shortcut you define in configuration. Asking an alias for help does not show the manual of the target command. Git reports what the alias expands to:
git config --global alias.co checkout
git co --help'co' is aliased to 'checkout'To read the real documentation, ask for the target command: git help checkout.
Mistyped commands and autocorrect
When you mistype a command, Git suggests the closest match:
git comit -m "Add notes"git: 'comit' is not a git command. See 'git --help'.
The most similar command is
commitThe behavior is controlled by help.autocorrect. Its meaning depends on the Git version, so check git help config on your machine. These values are widely supported:
| Value | Behavior |
|---|---|
| `0` (default) | Show the suggestion and stop |
| `1` | Run the suggestion immediately |
| A number above 1 | Wait that many tenths of a second, then run it |
Newer versions also accept words such as prompt and never.
git config --global help.autocorrect 0Think carefully before turning on immediate correction. A typo that autocorrects to a different command can change your repository without you intending it. Keeping suggestions only is the safer setting while you learn.
A workflow for getting unstuck
The diagram below shows a reasonable order for looking things up. Move to the next step only when the previous one does not answer your question.
Worked example
Suppose you made a commit with a typo in the message and want to fix it. You don't know the command.
- Search the command list for a likely word:
``bash git help -a | grep -i amend ``
Nothing matches, because amend is an option, not a command.
- Open the page for the command you used,
commit, and search for the word:
``bash git help commit ``
Inside the pager, type /--amend and press Enter. The OPTIONS entry says that --amend replaces the tip of the current branch by creating a new commit.
- Check the short form before you run it:
``bash git commit -h | grep amend ``
The usage line includes --amend, which confirms the flag exists in your version.
This path uses only local documentation and takes under a minute once the habit forms.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `No manual entry for git-commit` | Man pages are not installed | Install the documentation package for your distribution, or use `git help -w commit` |
| Help opens in a browser when you wanted the terminal | `help.format` is set to `web`, or you are on Windows | Use `git help -m commit`, or unset `help.format` |
| `git: 'xyz' is not a git command` | Typo, or the command comes from a missing tool | Run `git help -a` and check spelling |
| Script stops after `git <command> -h` | `-h` exits with status 129 | Remove the call from the script, or ignore the status |
| An option in a web tutorial is "unknown" | Your Git version is older or newer than the page | Compare `git --version` with the docs |
Summary
git <command> -hprints a short usage summary and needs no viewer.git help <command>andgit <command> --helpopen the full manual page.git help -alists commands,git help -glists guides, andgit help -clists configuration variables on recent versions.help.formatand the-m,-w,-ioptions control where the page opens.- Aliases report their expansion. Ask for the target command to read its page.
help.autocorrectcontrols whether Git only suggests or also runs the closest match.
Exercise
You want a quick reminder of the flags that git commit accepts, and you are inside a script that uses set -e. Which form do you use for an interactive session, and why should you not leave it in the script?
Show answer
In an interactive session, run git commit -h. It prints a short usage summary and needs no manual page viewer. Do not leave it in a script with set -e, because -h exits with status 129, which counts as a failure and stops the script.
Exercise
A manual page shows git commit [-m <msg>] [--] [<pathspec>...]. Which parts are optional, what does <msg> stand for, and what does -- do?
Show answer
Everything in square brackets is optional: the -m <msg> pair, the --, and the paths. <msg> is a placeholder for your commit message text. -- marks the end of options, so anything after it is read as a path even if it starts with a dash.
Exercise
You are on a machine with no man command and git help commit fails. Name two ways to read the commit documentation anyway.
Show answer
Run git help -w commit to open the HTML page in a browser, or use the online reference at git-scm.com/docs. You can also read the local HTML files in the folder printed by git --html-path. For a quick summary, git commit -h works without any viewer.
Exercise
You set git config --global alias.st status and then run git st --help. What do you see, and how do you read the real documentation?
Show answer
Git prints 'st' is aliased to 'status' instead of opening a manual page. To read the documentation, run git help status.
Exercise
You type git stauts and Git replies that the most similar command is status. What setting makes Git run status without asking, and why might you avoid it?
Show answer
Set help.autocorrect to 1, or to a number of tenths of a second to wait first. You might avoid it because a typo could be corrected to a different command that changes your repository. Leaving the value at 0 shows the suggestion and stops.