3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.46.0.288.g3a7362eb9f
10 .TH "GITCLI" "7" "2024-08-21" "Git 2\&.46\&.0\&.288\&.g3a7362" "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 given 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 ambiguities 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 the 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 asks 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 Splitting short options to separate words (prefer
184 \fBgit foo \-a \-b\fR
186 \fBgit foo \-ab\fR, the latter may not even work)\&.
197 When a command\-line option takes an argument, use the
199 form\&. In other words, write
202 \fBgit foo \-o Arg\fR
203 for short options, and
204 \fBgit foo \-\-long\-opt=Arg\fR
206 \fBgit foo \-\-long\-opt Arg\fR
207 for long options\&. An option that takes optional option\-argument must be written in the
220 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
221 \fBgit log \-1 HEAD\fR
223 \fBgit log \-1 HEAD \-\-\fR; the former will not work if you happen to have a file called
236 Many commands allow a long option
238 to be abbreviated only to their unique prefix (e\&.g\&. if there is no other option whose name begins with
239 \fBopt\fR, you may be able to spell
243 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\&.
244 \fB\-\-optimize\fR, to make a short prefix that used to be unique no longer unique\&.
246 .SH "ENHANCED OPTION PARSER"
248 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\&.
250 Here is a list of the facilities provided by this option parser\&.
253 Commands which have the enhanced option parser activated all understand a couple of magic command\-line options:
257 gives a pretty printed usage of the command\&.
264 usage: git describe [<options>] <commit\-ish>*
265 or: git describe [<options>] \-\-dirty
267 \-\-contains find the tag that comes after the commit
268 \-\-debug debug search strategy on stderr
270 \-\-tags use any tag, even unannotated
271 \-\-long always use long format
272 \-\-abbrev[=<n>] use <n> digits to display SHA\-1s
278 Note that some subcommand (e\&.g\&.
279 \fBgit grep\fR) may behave differently when there are things on the command line other than
282 without anything else on the command line is meant to consistently give the usage\&.
287 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\&.
289 .SS "Negating options"
291 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\&.
292 .SS "Aggregating short options"
294 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\&.
295 .SS "Abbreviating long options"
297 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\&.
298 .SS "Separating argument from the option"
300 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:
306 $ git foo \-\-long\-opt=Arg
307 $ git foo \-\-long\-opt Arg
315 However, this is \fBNOT\fR allowed for switches with an optional value, where the \fIstuck\fR form must be used:
321 $ git describe \-\-abbrev HEAD # correct
322 $ git describe \-\-abbrev=10 HEAD # correct
323 $ git describe \-\-abbrev 10 HEAD # NOT WHAT YOU MEANT
328 .SH "NOTES ON FREQUENTLY CONFUSED OPTIONS"
330 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\&.
342 option is used to ask a command that usually works on files in the working tree to
344 work with the index\&. For example,
345 \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
347 option, it looks for strings in the index\&.
360 option is used to ask a command that usually works on files in the working tree to
362 affect the index\&. For example,
363 \fBgit stash apply\fR
364 usually merges changes recorded in a stash entry to the working tree, but with the
366 option, it also merges changes to the index as well\&.
369 \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\&.
371 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\&.
373 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\&.
385 \fB\-\-cached\fR, which is used to ask a command to only work on the index, not the working tree\&.
397 is the opposite, to ask a command to work on the working tree only, not the index\&.
408 The two options can be specified together to ask a command to work on both the index and the working tree\&.
412 Part of the \fBgit\fR(1) suite