Getting Help in Git
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 want | Command | What you get |
|---|---|---|
| A quick reminder of the options | git <command> -h | A short summary, printed in the terminal |
| The full explanation, with examples | git help <command> or git <command> --help | The manual page for that command |
| An introduction to a topic | git 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:
git mv -husage: 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 coneThe 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.
| Sign | Meaning | In the output above |
|---|---|---|
<source> | A placeholder: type your own value here | The file you want to move |
[-f] | Square brackets: this part is optional | You may add -f, or leave it out |
<source>... | Three dots: one or more of these | Several files can be moved into a folder at once |
-v, --verbose | A short and a long name for the same option | git mv -v and git mv --verbose do the same |
--[no-]verbose | The option also has an opposite | --verbose turns it on, --no-verbose turns it off |
Two more signs appear in other commands:
| Sign | Meaning | Example |
|---|---|---|
-q | --quiet | A vertical bar: choose one or the other | git init [-q | --quiet] |
-- | Two dashes alone: everything after this is a file name, not an option | git 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.
The Full Manual with git help
When the short summary is not enough, open the manual page:
git help mvgit mv --help opens the same page. Where it opens depends on your system:
| System | Where the manual opens |
|---|---|
| Windows | In your web browser, as a page stored on your computer |
| macOS and Linux | In 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:
| Key | What it does |
|---|---|
| Space | Next screen |
b | Back one screen |
/word then Enter | Search for "word" |
n | Jump to the next match |
q | Quit and return to the terminal |
Every manual page has the same sections, in the same order:
| Section | What it tells you |
|---|---|
| NAME | The command and one line about what it does |
| SYNOPSIS | The usage lines, as in -h |
| DESCRIPTION | What the command does, in full |
| OPTIONS | Every option, explained |
| EXAMPLES | Real 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:
git help -gThe 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:
| Command | What it opens |
|---|---|
git help everyday | A small set of commands that covers most daily work |
git help glossary | Every Git word, explained |
git help faq | Answers 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:
git stautsgit: 'stauts' is not a git command. See 'git --help'.
The most similar command is
statusNothing 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:
mkdir git-practice
cd git-practice
git init
git statusInitialized 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
git rm -husage: 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 characterThe 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.)
Key Takeaways
Quick reference
| Command | It is used to |
|---|---|
git <command> -h | Print a short summary of the command's options |
git help <command> | Open the full manual page for a command |
git <command> --help | The same as git help <command> |
git help -g | List the built-in guides |
git help everyday | Open the guide to the most-used commands |
git help glossary | Open the glossary of Git words |
git help -a | List every Git command |
git help -c | List every setting name for git config |
Was this tutorial helpful?