gitcli(7) (original) (raw)
From the Git 1.5.4 series and further, many Git commands (not all of them at the time of the writing though) come with an enhanced option parser.
Here is a list of the facilities provided by this option parser.
Magic Options
Commands which have the enhanced option parser activated all understand a couple of magic command-line options:
-h
gives a pretty printed usage of the command.
$ git describe -h usage: git describe [] * or: git describe [] --dirty
--contains find the tag that comes after the commit
--debug debug search strategy on stderr
--all use any ref
--tags use any tag, even unannotated
--long always use long format
--abbrev[=<n>] use <n> digits to display SHA-1s
Note that some subcommand (e.g. git
grep
) may behave differently when there are things on the command line other than -h
, but git
subcmd
-h
without anything else on the command line is meant to consistently give the usage.
--help-all
Some Git commands take options that are only used for plumbing or that are deprecated, and such options are hidden from the default usage. This option gives the full list of options.
Negating options
Options with long option names can be negated by prefixing --no-
. For example, git
branch
has the option --track
which is on by default. You can use --no-track
to override that behaviour. The same goes for --color
and --no-color
.
Options trump configuration and environment
When there is a configuration variable or an environment variable that tweak the behaviour of an aspect of a Git command, and also a command line option that tweaks the same, the command line option overrides what the configuration and/or environment variable say.
For example, the user.name
configuration variable is used to specify the human-readable name used by the git
commit
command to record the author and the committer name in a newly created commit. The GIT_AUTHOR_NAME
environment variable, if set, takes precedence when deciding what author name to record. The --author=
__command line option of the git
commit
command, when given, takes precedence over these two sources of information.
Aggregating short options
Commands that support the enhanced option parser allow you to aggregate short options. This means that you can for example use git
rm
-rf
orgit
clean
-fdx
.
Abbreviating long options
Commands that support the enhanced option parser accepts unique prefix of a long option as if it is fully spelled out, but use this with a caution. For example, git
commit
--amen
behaves as if you typed git
commit
--amend
, but that is true only until a later version of Git introduces another option that shares the same prefix, e.g. git
commit
--amenity
option.
Separating argument from the option
You can write the mandatory option parameter to an option as a separate word on the command line. That means that all the following uses work:
$ git foo --long-opt=Arg $ git foo --long-opt Arg $ git foo -oArg $ git foo -o Arg
However, this is NOT allowed for switches with an optional value, where the_stuck_ form must be used:
$ git describe --abbrev HEAD # correct $ git describe --abbrev=10 HEAD # correct $ git describe --abbrev 10 HEAD # NOT WHAT YOU MEANT