3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
10 .TH "GITCLI" "7" "2023\-06\-01" "Git 2\&.41\&.0" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 gitcli \- Git command\-line interface and conventions
37 This manual describes the convention used throughout Git CLI\&.
39 Many commands take revisions (most often "commits", but sometimes "tree\-ish", depending on the context and command) and paths as their arguments\&. Here are the rules:
49 Options come first and then args\&. A subcommand may take dashed options (which may take their own arguments, e\&.g\&. "\-\-max\-parents 2") and arguments\&. You SHOULD give dashed options first and then arguments\&. Some commands may accept dashed options after you have already gave non\-option arguments (which may make the command ambiguous), but you should not rely on it (because eventually we may find a way to fix these ambiguity by enforcing the "options then args" rule)\&.
60 Revisions come first and then paths\&. E\&.g\&. in
61 \fBgit diff v1\&.0 v2\&.0 arch/x86 include/asm\-x86\fR,
68 \fBinclude/asm\-x86\fR
80 When an argument can be misunderstood as either a revision or a path, they can be disambiguated by placing
82 between them\&. E\&.g\&.
83 \fBgit diff \-\- HEAD\fR
84 is, "I have a file called HEAD in my work tree\&. Please show changes between the version I staged in the index and what I have in the work tree for that file", not "show difference between the HEAD commit and the work tree as a whole"\&. You can say
85 \fBgit diff HEAD \-\-\fR
86 to ask for the latter\&.
97 Without disambiguating
98 \fB\-\-\fR, Git makes a reasonable guess, but errors out and asking you to disambiguate when ambiguous\&. E\&.g\&. if you have a file called HEAD in your work tree,
100 is ambiguous, and you have to say either
101 \fBgit diff HEAD \-\-\fR
103 \fBgit diff \-\- HEAD\fR
117 disambiguates revisions and paths in some commands, it cannot be used for those commands to separate options and revisions\&. You can use
118 \fB\-\-end\-of\-options\fR
119 for this (it also works for commands that do not distinguish between revisions in paths, in which case it is simply an alias for
122 When writing a script that is expected to handle random user\-input, it is a good practice to make it explicit which arguments are which by placing disambiguating
124 at appropriate places\&.
135 Many commands allow wildcards in paths, but you need to protect them from getting globbed by the shell\&. These two mean different things:
142 $ git restore \e*\&.c
148 The former lets your shell expand the fileglob, and you are asking the dot\-C files in your working tree to be overwritten with the version in the index\&. The latter passes the
150 to Git, and you are asking the paths in the index that match the pattern to be checked out to your working tree\&. After running
151 \fBgit add hello\&.c; rm hello\&.c\fR, you will
155 in your working tree with the former, but with the latter you will\&.
166 Just as the filesystem
168 (period) refers to the current directory, using a
170 as a repository name in Git (a dot\-repository) is a relative path and means your current repository\&.
173 Here are the rules regarding the "flags" that you should follow when you are scripting Git:
183 It\(cqs preferred to use the non\-dashed form of Git commands, which means that you should prefer
197 Splitting short options to separate words (prefer
198 \fBgit foo \-a \-b\fR
200 \fBgit foo \-ab\fR, the latter may not even work)\&.
211 When a command\-line option takes an argument, use the
213 form\&. In other words, write
216 \fBgit foo \-o Arg\fR
217 for short options, and
218 \fBgit foo \-\-long\-opt=Arg\fR
220 \fBgit foo \-\-long\-opt Arg\fR
221 for long options\&. An option that takes optional option\-argument must be written in the
234 When you give a revision parameter to a command, make sure the parameter is not ambiguous with a name of a file in the work tree\&. E\&.g\&. do not write
235 \fBgit log \-1 HEAD\fR
237 \fBgit log \-1 HEAD \-\-\fR; the former will not work if you happen to have a file called
250 Many commands allow a long option
252 to be abbreviated only to their unique prefix (e\&.g\&. if there is no other option whose name begins with
253 \fBopt\fR, you may be able to spell
257 flag), but you should fully spell them out when writing your scripts; later versions of Git may introduce a new option whose name shares the same prefix, e\&.g\&.
258 \fB\-\-optimize\fR, to make a short prefix that used to be unique no longer unique\&.
260 .SH "ENHANCED OPTION PARSER"
262 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\&.
264 Here is a list of the facilities provided by this option parser\&.
267 Commands which have the enhanced option parser activated all understand a couple of magic command\-line options:
271 gives a pretty printed usage of the command\&.
278 usage: git describe [<options>] <commit\-ish>*
279 or: git describe [<options>] \-\-dirty
281 \-\-contains find the tag that comes after the commit
282 \-\-debug debug search strategy on stderr
284 \-\-tags use any tag, even unannotated
285 \-\-long always use long format
286 \-\-abbrev[=<n>] use <n> digits to display SHA\-1s
292 Note that some subcommand (e\&.g\&.
293 \fBgit grep\fR) may behave differently when there are things on the command line other than
296 without anything else on the command line is meant to consistently give the usage\&.
301 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\&.
303 .SS "Negating options"
305 Options with long option names can be negated by prefixing \fB\-\-no\-\fR\&. For example, \fBgit branch\fR has the option \fB\-\-track\fR which is \fIon\fR by default\&. You can use \fB\-\-no\-track\fR to override that behaviour\&. The same goes for \fB\-\-color\fR and \fB\-\-no\-color\fR\&.
306 .SS "Aggregating short options"
308 Commands that support the enhanced option parser allow you to aggregate short options\&. This means that you can for example use \fBgit rm \-rf\fR or \fBgit clean \-fdx\fR\&.
309 .SS "Abbreviating long options"
311 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, \fBgit commit \-\-amen\fR behaves as if you typed \fBgit commit \-\-amend\fR, but that is true only until a later version of Git introduces another option that shares the same prefix, e\&.g\&. \fBgit commit \-\-amenity\fR option\&.
312 .SS "Separating argument from the option"
314 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:
320 $ git foo \-\-long\-opt=Arg
321 $ git foo \-\-long\-opt Arg
330 However, this is \fBNOT\fR allowed for switches with an optional value, where the \fIstuck\fR form must be used:
336 $ git describe \-\-abbrev HEAD # correct
337 $ git describe \-\-abbrev=10 HEAD # correct
338 $ git describe \-\-abbrev 10 HEAD # NOT WHAT YOU MEANT
344 .SH "NOTES ON FREQUENTLY CONFUSED OPTIONS"
346 Many commands that can work on files in the working tree and/or in the index can take \fB\-\-cached\fR and/or \fB\-\-index\fR options\&. Sometimes people incorrectly think that, because the index was originally called cache, these two are synonyms\&. They are \fBnot\fR \(em these two options mean very different things\&.
358 option is used to ask a command that usually works on files in the working tree to
360 work with the index\&. For example,
361 \fBgit grep\fR, when used without a commit to specify from which commit to look for strings in, usually works on files in the working tree, but with the
363 option, it looks for strings in the index\&.
376 option is used to ask a command that usually works on files in the working tree to
378 affect the index\&. For example,
379 \fBgit stash apply\fR
380 usually merges changes recorded in a stash entry to the working tree, but with the
382 option, it also merges changes to the index as well\&.
385 \fBgit apply\fR command can be used with \fB\-\-cached\fR and \fB\-\-index\fR (but not at the same time)\&. Usually the command only affects the files in the working tree, but with \fB\-\-index\fR, it patches both the files and their index entries, and with \fB\-\-cached\fR, it modifies only the index entries\&.
387 See also \m[blue]\fBhttps://lore\&.kernel\&.org/git/7v64clg5u9\&.fsf@assigned\-by\-dhcp\&.cox\&.net/\fR\m[] and \m[blue]\fBhttps://lore\&.kernel\&.org/git/7vy7ej9g38\&.fsf@gitster\&.siamese\&.dyndns\&.org/\fR\m[] for further information\&.
389 Some other commands that also work on files in the working tree and/or in the index can take \fB\-\-staged\fR and/or \fB\-\-worktree\fR\&.
401 \fB\-\-cached\fR, which is used to ask a command to only work on the index, not the working tree\&.
413 is the opposite, to ask a command to work on the working tree only, not the index\&.
424 The two options can be specified together to ask a command to work on both the index and the working tree\&.
428 Part of the \fBgit\fR(1) suite