Sub topic 10
Finding help in Git
This chapter covers the built-in help Git ships with. It assumes you have already installed Git and checked it with git --version. You should also be able to run simple commands in a terminal. Git has many commands and options, so knowing how to look them up is more useful than memorizing them.
Three ways to ask for help
Git offers the same manual pages through several commands. All of them open documentation for a command without needing an internet connection.
git help commit
git commit --helpBoth forms open the manual page for git commit. On most systems the page appears in a pager, which is a program that shows long text one screen at a time. The page also opens in a web browser on some Windows installs.
The third form is man, which works on macOS and Linux:
man git-commitThe git-commit spelling is the actual name of the manual page. Git rewrites git help commit into this name for you.
Quick reminders with -h
A full manual page is long. When you only need to remember which options exist, use the short form:
git commit -hThis prints a usage line and a list of options directly in the terminal, then returns you to the prompt. It does not open a pager.
| Command | What you get | Best used when |
|---|---|---|
| `git help <command>` | Full manual page | You need details and examples |
| `git <command> --help` | Same manual page | You are already typing the command |
| `git <command> -h` | Short usage summary in the terminal | You forgot an option name |
| `git help -a` | List of all commands | You want to see what exists |
| `git help -g` | List of concept guides | You want background reading |
Reading a manual page
Manual pages follow a standard layout. Knowing it lets you jump to the part you need.
- NAME gives a one-line description.
- SYNOPSIS shows the command's syntax. Square brackets mean an option is optional, a vertical bar means "one of these", and
<name>marks a value you supply. - DESCRIPTION explains what the command does.
- OPTIONS lists each flag with an explanation.
- EXAMPLES appears in some pages and shows typical use.
In the pager, press the space bar to go forward one screen, b to go back, / followed by a word to search, and q to quit. Searching is the fastest way to find an option. Type /--amend and press Enter to jump to that option's entry. Press n to move to the next match.
Concept guides
Git also includes guides that explain ideas instead of single commands. List them with:
git help -gYou will see entries such as gittutorial, gitglossary, and gitworkflows. Open one the same way as a command page:
git help tutorial
git help glossaryThe glossary is useful at this stage. It defines terms such as index, working tree, and HEAD, which you will meet again as you use Git.
Finding a command you cannot name
Sometimes you know what you want but not the command. Git helps in two ways.
First, git help -a prints every available command with a short description. The list is long, so search it in the pager or pipe it through grep:
git help -a | grep -i branchSecond, Git suggests corrections when you mistype a command. If you type git comit, Git replies that the command does not exist and names the closest match, commit. It only suggests the fix. It does not run it unless you set help.autocorrect in your configuration, and you should leave that off while learning so that typos do not run unexpected commands.
Where to look when built-in help is not enough
The built-in pages describe exactly the version you installed, which makes them accurate for your machine. They are written as reference material, so they can feel dense for a beginner. When a page is hard to follow, two other sources help:
- The online Pro Git book at git-scm.com, which explains concepts in a teaching style.
- The reference documentation at git-scm.com/docs, which mirrors the manual pages in a browser.
If you read the online documentation, check that it matches your version. A newer page may describe an option your installed Git does not have. Compare it against git --version and the local git help output.
Common errors
- "No manual entry for git-xyz". The command name is wrong, or the manual pages were not installed. Check the spelling with
git help -a. - A page opens in an editor-like screen and seems frozen. You are in the pager. Press
q. git helpopens a browser you did not expect. Your system is set to use HTML help. You can change this withgit config --global help.format manon systems where man pages are available.- Help for a subcommand is missing. Some commands take a subcommand, such as
git remote add. The manual page belongs to the main command, so rungit help remote.
Exercise
You want to see every option of git log and then quickly check the name of one flag you forgot. Which two commands would you use, and why is the second one faster?
Show answer
Use git help log (or git log --help) to read the full manual page, and git log -h for the quick check. The -h form prints a short usage summary straight into the terminal and returns to the prompt. It avoids opening the pager, so you do not need to scroll, search, or press q.
Exercise
Find the manual page that defines the word "index" in Git terms. Which command opens it, and what key sequence in the pager finds the word?
Show answer
Run git help glossary to open the Git glossary. In the pager, type /index and press Enter to jump to the first match, then press n for further matches. Press q to quit.