1GITCLI(7)                         Git Manual                         GITCLI(7)
2
3
4

NAME

6       gitcli - git command line interface and conventions
7

SYNOPSIS

9       gitcli
10

DESCRIPTION

12       This manual describes the convention used throughout git CLI.
13
14       Many commands take revisions (most often "commits", but sometimes
15       "tree-ish", depending on the context and command) and paths as their
16       arguments. Here are the rules:
17
18       ·   Revisions come first and then paths. E.g. in git diff v1.0 v2.0
19           arch/x86 include/asm-x86, v1.0 and v2.0 are revisions and arch/x86
20           and include/asm-x86 are paths.
21
22       ·   When an argument can be misunderstood as either a revision or a
23           path, they can be disambiguated by placing -- between them. E.g.
24           git diff -- HEAD is, "I have a file called HEAD in my work tree.
25           Please show changes between the version I staged in the index and
26           what I have in the work tree for that file". not "show difference
27           between the HEAD commit and the work tree as a whole". You can say
28           git diff HEAD -- to ask for the latter.
29
30       ·   Without disambiguating --, git makes a reasonable guess, but errors
31           out and asking you to disambiguate when ambiguous. E.g. if you have
32           a file called HEAD in your work tree, git diff HEAD is ambiguous,
33           and you have to say either git diff HEAD -- or git diff -- HEAD to
34           disambiguate.
35
36       When writing a script that is expected to handle random user-input, it
37       is a good practice to make it explicit which arguments are which by
38       placing disambiguating -- at appropriate places.
39
40       Here are the rules regarding the "flags" that you should follow when
41       you are scripting git:
42
43       ·   it’s preferred to use the non dashed form of git commands, which
44           means that you should prefer git foo to git-foo.
45
46       ·   splitting short options to separate words (prefer git foo -a -b to
47           git foo -ab, the latter may not even work).
48
49       ·   when a command line option takes an argument, use the sticked form.
50           In other words, write git foo -oArg instead of git foo -o Arg for
51           short options, and git foo --long-opt=Arg instead of git foo
52           --long-opt Arg for long options. An option that takes optional
53           option-argument must be written in the sticked form.
54
55       ·   when you give a revision parameter to a command, make sure the
56           parameter is not ambiguous with a name of a file in the work tree.
57           E.g. do not write git log -1 HEAD but write git log -1 HEAD --; the
58           former will not work if you happen to have a file called HEAD in
59           the work tree.
60

ENHANCED OPTION PARSER

62       From the git 1.5.4 series and further, many git commands (not all of
63       them at the time of the writing though) come with an enhanced option
64       parser.
65
66       Here is an exhaustive list of the facilities provided by this option
67       parser.
68
69   Magic Options
70       Commands which have the enhanced option parser activated all understand
71       a couple of magic command line options:
72
73       -h
74           gives a pretty printed usage of the command.
75
76               $ git describe -h
77               usage: git describe [options] <committish>*
78
79                   --contains            find the tag that comes after the commit
80                   --debug               debug search strategy on stderr
81                   --all                 use any ref in .git/refs
82                   --tags                use any tag in .git/refs/tags
83                   --abbrev [<n>]        use <n> digits to display SHA-1s
84                   --candidates <n>      consider <n> most recent tags (default: 10)
85
86
87       --help-all
88           Some git commands take options that are only used for plumbing or
89           that are deprecated, and such options are hidden from the default
90           usage. This option gives the full list of options.
91
92   Negating options
93       Options with long option names can be negated by prefixing --no-. For
94       example, git branch has the option --track which is on by default. You
95       can use --no-track to override that behaviour. The same goes for
96       --color and --no-color.
97
98   Aggregating short options
99       Commands that support the enhanced option parser allow you to aggregate
100       short options. This means that you can for example use git rm -rf or
101       git clean -fdx.
102
103   Separating argument from the option
104       You can write the mandatory option parameter to an option as a separate
105       word on the command line. That means that all the following uses work:
106
107           $ git foo --long-opt=Arg
108           $ git foo --long-opt Arg
109           $ git foo -oArg
110           $ git foo -o Arg
111
112
113       However, this is NOT allowed for switches with an optional value, where
114       the sticked form must be used:
115
116           $ git describe --abbrev HEAD     # correct
117           $ git describe --abbrev=10 HEAD  # correct
118           $ git describe --abbrev 10 HEAD  # NOT WHAT YOU MEANT
119
120

NOTES ON FREQUENTLY CONFUSED OPTIONS

122       Many commands that can work on files in the working tree and/or in the
123       index can take --cached and/or --index options. Sometimes people
124       incorrectly think that, because the index was originally called cache,
125       these two are synonyms. They are not — these two options mean very
126       different things.
127
128       ·   The --cached option is used to ask a command that usually works on
129           files in the working tree to only work with the index. For example,
130           git grep, when used without a commit to specify from which commit
131           to look for strings in, usually works on files in the working tree,
132           but with the --cached option, it looks for strings in the index.
133
134       ·   The --index option is used to ask a command that usually works on
135           files in the working tree to also affect the index. For example,
136           git stash apply usually merges changes recorded in a stash to the
137           working tree, but with the --index option, it also merges changes
138           to the index as well.
139
140       git apply command can be used with --cached and --index (but not at the
141       same time). Usually the command only affects the files in the working
142       tree, but with --index, it patches both the files and their index
143       entries, and with --cached, it modifies only the index entries.
144
145       See also http://marc.info/?l=git&m=116563135620359 and
146       http://marc.info/?l=git&m=119150393620273 for further information.
147

DOCUMENTATION

149       Documentation by Pierre Habouzit and the git-list
150       <git@vger.kernel.org[1]>.
151

GIT

153       Part of the git(1) suite
154

NOTES

156        1. git@vger.kernel.org
157           mailto:git@vger.kernel.org
158
159
160
161Git 1.7.1                         08/16/2017                         GITCLI(7)
Impressum