3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.34.1.182.ge773545c7f
10 .TH "GITCLI" "7" "12/10/2021" "Git 2\&.34\&.1\&.182\&.ge77354" "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 Revisions come first and then paths\&. E\&.g\&. in
50 \fBgit diff v1\&.0 v2\&.0 arch/x86 include/asm\-x86\fR,
57 \fBinclude/asm\-x86\fR
69 When an argument can be misunderstood as either a revision or a path, they can be disambiguated by placing
71 between them\&. E\&.g\&.
72 \fBgit diff \-\- HEAD\fR
73 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
74 \fBgit diff HEAD \-\-\fR
75 to ask for the latter\&.
86 Without disambiguating
87 \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,
89 is ambiguous, and you have to say either
90 \fBgit diff HEAD \-\-\fR
92 \fBgit diff \-\- HEAD\fR
106 disambiguates revisions and paths in some commands, it cannot be used for those commands to separate options and revisions\&. You can use
107 \fB\-\-end\-of\-options\fR
108 for this (it also works for commands that do not distinguish between revisions in paths, in which case it is simply an alias for
111 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
113 at appropriate places\&.
124 Many commands allow wildcards in paths, but you need to protect them from getting globbed by the shell\&. These two mean different things:
131 $ git restore \e*\&.c
137 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
139 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
140 \fBgit add hello\&.c; rm hello\&.c\fR, you will
144 in your working tree with the former, but with the latter you will\&.
155 Just as the filesystem
157 (period) refers to the current directory, using a
159 as a repository name in Git (a dot\-repository) is a relative path and means your current repository\&.
162 Here are the rules regarding the "flags" that you should follow when you are scripting Git:
172 it\(cqs preferred to use the non\-dashed form of Git commands, which means that you should prefer
186 splitting short options to separate words (prefer
187 \fBgit foo \-a \-b\fR
189 \fBgit foo \-ab\fR, the latter may not even work)\&.
200 when a command\-line option takes an argument, use the
202 form\&. In other words, write
205 \fBgit foo \-o Arg\fR
206 for short options, and
207 \fBgit foo \-\-long\-opt=Arg\fR
209 \fBgit foo \-\-long\-opt Arg\fR
210 for long options\&. An option that takes optional option\-argument must be written in the
223 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
224 \fBgit log \-1 HEAD\fR
226 \fBgit log \-1 HEAD \-\-\fR; the former will not work if you happen to have a file called
239 many commands allow a long option
241 to be abbreviated only to their unique prefix (e\&.g\&. if there is no other option whose name begins with
242 \fBopt\fR, you may be able to spell
246 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\&.
247 \fB\-\-optimize\fR, to make a short prefix that used to be unique no longer unique\&.
249 .SH "ENHANCED OPTION PARSER"
251 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\&.
253 Here is a list of the facilities provided by this option parser\&.
256 Commands which have the enhanced option parser activated all understand a couple of magic command\-line options:
260 gives a pretty printed usage of the command\&.
267 usage: git describe [<options>] <commit\-ish>*
268 or: git describe [<options>] \-\-dirty
270 \-\-contains find the tag that comes after the commit
271 \-\-debug debug search strategy on stderr
273 \-\-tags use any tag, even unannotated
274 \-\-long always use long format
275 \-\-abbrev[=<n>] use <n> digits to display SHA\-1s
281 Note that some subcommand (e\&.g\&.
282 \fBgit grep\fR) may behave differently when there are things on the command line other than
285 without anything else on the command line is meant to consistently give the usage\&.
290 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\&.
292 .SS "Negating options"
294 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\&.
295 .SS "Aggregating short options"
297 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\&.
298 .SS "Abbreviating long options"
300 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\&.
301 .SS "Separating argument from the option"
303 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:
309 $ git foo \-\-long\-opt=Arg
310 $ git foo \-\-long\-opt Arg
319 However, this is \fBNOT\fR allowed for switches with an optional value, where the \fIstuck\fR form must be used:
325 $ git describe \-\-abbrev HEAD # correct
326 $ git describe \-\-abbrev=10 HEAD # correct
327 $ git describe \-\-abbrev 10 HEAD # NOT WHAT YOU MEANT
333 .SH "NOTES ON FREQUENTLY CONFUSED OPTIONS"
335 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\&.
347 option is used to ask a command that usually works on files in the working tree to
349 work with the index\&. For example,
350 \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
352 option, it looks for strings in the index\&.
365 option is used to ask a command that usually works on files in the working tree to
367 affect the index\&. For example,
368 \fBgit stash apply\fR
369 usually merges changes recorded in a stash entry to the working tree, but with the
371 option, it also merges changes to the index as well\&.
374 \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\&.
376 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\&.
378 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\&.
390 \fB\-\-cached\fR, which is used to ask a command to only work on the index, not the working tree\&.
402 is the opposite, to ask a command to work on the working tree only, not the index\&.
413 The two options can be specified together to ask a command to work on both the index and the working tree\&.
417 Part of the \fBgit\fR(1) suite