Getting Help in Git

Updated · 10 min read
easyGit 2.53githelpdocumentationbasics

Git has more than 150 commands, and many of them have dozens of options. Nobody remembers them all. Developers with ten years of experience look things up every day, and the fastest place to look is Git itself.

Git carries its whole manual with it, so help works without an internet connection. In this lesson, you will learn the three ways to ask Git for help, how to read what it answers, and how Git points you in the right direction while you work.

Three Ways to Ask for Help

You wantCommandWhat you get
A quick reminder of the optionsgit <command> -hA short summary, printed in the terminal
The full explanation, with examplesgit help <command> or git <command> --helpThe manual page for that command
An introduction to a topicgit help <guide>A guide such as everyday or glossary

<command> is a placeholder. Replace it with a real command name, without the angle brackets: git commit -h, git help commit.

The Quick Summary with -h

When you know the command but forgot an option, add -h. Here is the summary for git mv, the command that renames or moves a file:

Terminal
git mv -h
Output
usage: git mv [-v] [-f] [-n] [-k] <source> <destination>
   or: git mv [-v] [-f] [-n] [-k] <source>... <destination-directory>
 
    -v, --[no-]verbose    be verbose
    -n, --[no-]dry-run    dry run
    -f, --[no-]force      force move/rename even if target exists
    -k                    skip move/rename errors
    --[no-]sparse         allow updating entries outside of the sparse-checkout cone

The summary has two parts. The lines that start with usage: and or: show the forms the command can take. The list below them shows the options, each with a few words of explanation.

How to Read a Usage Line

Usage lines are written in a small sign language. The same signs are used by Git, by its manual and by most other terminal programs, so they are worth learning once.

SignMeaningIn the output above
<source>A placeholder: type your own value hereThe file you want to move
[-f]Square brackets: this part is optionalYou may add -f, or leave it out
<source>...Three dots: one or more of theseSeveral files can be moved into a folder at once
-v, --verboseA short and a long name for the same optiongit mv -v and git mv --verbose do the same
--[no-]verboseThe option also has an opposite--verbose turns it on, --no-verbose turns it off

Two more signs appear in other commands:

SignMeaningExample
-q | --quietA vertical bar: choose one or the othergit init [-q | --quiet]
--Two dashes alone: everything after this is a file name, not an optiongit add -- notes.txt

So the first usage line of git mv reads: "type git mv, then any of the four optional flags, then the file to move, then its new name". For example, git mv notes.txt ideas.txt renames notes.txt to ideas.txt.

Reading a usage line

The Full Manual with git help

When the short summary is not enough, open the manual page:

Terminal
git help mv

git mv --help opens the same page. Where it opens depends on your system:

SystemWhere the manual opens
WindowsIn your web browser, as a page stored on your computer
macOS and LinuxIn the terminal, one screen at a time

In the terminal, the manual is shown by a program called a pager. These keys move you around:

KeyWhat it does
SpaceNext screen
bBack one screen
/word then EnterSearch for "word"
nJump to the next match
qQuit and return to the terminal

Every manual page has the same sections, in the same order:

SectionWhat it tells you
NAMEThe command and one line about what it does
SYNOPSISThe usage lines, as in -h
DESCRIPTIONWhat the command does, in full
OPTIONSEvery option, explained
EXAMPLESReal commands for common situations (not every page has this section)

Built-In Guides

Git's manual also contains guides about ideas, not single commands. git help -g lists them:

Terminal
git help -g
Output
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
   namespaces       Git namespaces
   remote-helpers   Helper programs to interact with remote repositories
   submodules       Mounting one repository inside another
   tutorial         A tutorial introduction to Git
   tutorial-2       A tutorial introduction to Git: part two
   workflows        An overview of recommended workflows with Git
 
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

Open one by its name. Three are useful from the start:

CommandWhat it opens
git help everydayA small set of commands that covers most daily work
git help glossaryEvery Git word, explained
git help faqAnswers to questions people ask often

Two more lists are worth knowing. git help -a prints every Git command with a one-line description, and git help -c prints the name of every setting that git config understands.

Git Helps You as You Work

You often don't have to ask. Git's own messages tell you what went wrong and what to do next.

Typing mistakes. If you mistype a command, Git suggests the closest real one:

Terminal
git stauts
Output
git: 'stauts' is not a git command. See 'git --help'.
 
The most similar command is
	status

Nothing happened and nothing was harmed. Type the command again, correctly.

Next steps. Many commands end their output with advice. Create a practice repository and ask for its status:

Terminal
mkdir git-practice
cd git-practice
git init
git status
Output
Initialized empty Git repository in /home/navika/projects/git-practice/.git/
On branch main
 
No commits yet
 
nothing to commit (create/copy files and use "git add" to track)

The last line tells you the next step: create a file, then use git add. Later in the course you will see git status suggest the exact command for undoing a change. Lines that begin with hint: are the same kind of advice.

Reading the messages is a skill. When a command fails, read Git's whole answer before you search online. Very often the fix is in the last two lines.

Help Outside the Terminal

The same manual pages are online at git-scm.com/docs, where they are easier to search and to link to. The same site has the book Pro Git, which is free to read and is the standard longer text on Git.

When you search the web for a Git problem, check the date of the answer. Advice from before 2019 uses git checkout for tasks that git switch and git restore now do more safely.

Common Mistakes

Getting stuck in the manual. The manual page fills the terminal and typing commands does nothing. You are in the pager. Press q.

Mixing up -h and --help. They are not two spellings of one thing. -h prints a few lines and returns. --help opens the full manual. Start with -h.

Typing the angle brackets. In git help <command>, the brackets mark a placeholder. Type git help commit, not git help <commit>.

Running a command from the web without reading it. Before you paste a command you don't understand, look up each option with -h. This matters most for options such as --force and --hard, which can delete work.

Ignoring Git's output. Beginners often see a block of text, assume it is an error and stop reading. Most of the time it is a normal report with a helpful last line.

Practice

Challenge: find an option yourself. git rm removes a file from a project. Suppose you want to see what git rm would remove, without removing anything. Use -h to find the option that does this.

What does Git print? Before you open the solution, guess the name of the option. The summary for git mv earlier in this lesson has an option with the same job.

Show solution
Terminal
git rm -h
Output
usage: git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]
              [--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]
              [--] [<pathspec>...]
 
    -n, --[no-]dry-run    dry run
    -q, --[no-]quiet      do not list removed files
    --[no-]cached         only remove from the index
    -f, --[no-]force      override the up-to-date check
    -r                    allow recursive removal
    --[no-]ignore-unmatch exit with a zero status even if nothing matched
    --[no-]sparse         allow updating entries outside of the sparse-checkout cone
    --[no-]pathspec-from-file <file>
                          read pathspec from file
    --[no-]pathspec-file-nul
                          with --pathspec-from-file, pathspec elements are separated with NUL character

The option is -n, or --dry-run in its long form. A dry run is a rehearsal: the command reports what it would do and changes nothing. Many Git commands have it, and it is a good habit before any command that deletes.

You can also read the usage line now. [-f | --force] is optional and has two spellings. [--] separates options from file names. [<pathspec>...] means one or more files or folders.

Try the manual. Run git help glossary, search for the word commit by typing /commit and pressing Enter, and leave with q. (On Windows the glossary opens in your browser, so use the browser's own search.)

Quick check: Getting help in Git

4 questions
1Which command prints a short summary of the options of git commit in the terminal?
2The manual page fills your terminal and typing does nothing. Which key gets you out?
3In a usage line, what do square brackets mean, as in git mv [-f] <source> <destination>?
4You type git stauts by mistake. What does Git do?

Key Takeaways

Quick reference

CommandIt is used to
git <command> -hPrint a short summary of the command's options
git help <command>Open the full manual page for a command
git <command> --helpThe same as git help <command>
git help -gList the built-in guides
git help everydayOpen the guide to the most-used commands
git help glossaryOpen the glossary of Git words
git help -aList every Git command
git help -cList every setting name for git config

Was this tutorial helpful?

Lesson 7 of 106