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.48.0.rc0.140.g76cf4f61c8
10 .TH "GITCLI" "7" "2024-12-26" "Git 2\&.48\&.0\&.rc0\&.140\&.g" "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
66 \fBinclude/asm\-x86\fR,
73 \fBinclude/asm\-x86\fR
85 When an argument can be misunderstood as either a revision or a path, they can be disambiguated by placing
87 between them\&. E\&.g\&.
92 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
97 to ask for the latter\&.
108 Without disambiguating
109 \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,
113 is ambiguous, and you have to say either
136 disambiguates revisions and paths in some commands, it cannot be used for those commands to separate options and revisions\&. You can use
137 \fB\-\-end\-of\-options\fR
138 for this (it also works for commands that do not distinguish between revisions in paths, in which case it is simply an alias for
141 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
143 at appropriate places\&.
154 Many commands allow wildcards in paths, but you need to protect them from getting globbed by the shell\&. These two mean different things:
161 $ git restore \e*\&.c
167 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 *\&.\fBc\fR
168 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
173 \fBhello\&.c\fR, you will
177 in your working tree with the former, but with the latter you will\&.
188 Just as the filesystem
190 (period) refers to the current directory, using a
192 as a repository name in Git (a dot\-repository) is a relative path and means your current repository\&.
195 Here are the rules regarding the "flags" that you should follow when you are scripting Git:
205 Splitting short options to separate words (prefer
213 \fB\-ab\fR, the latter may not even work)\&.
224 When a command\-line option takes an argument, use the
226 form\&. In other words, write
235 for short options, and
238 \fB\-\-long\-opt=Arg\fR
244 for long options\&. An option that takes optional option\-argument must be written in the
257 Despite the above suggestion, when Arg is a path relative to the home directory of a user, e\&.g\&. ~/directory/file or ~u/d/f, you may want to use the separate form, e\&.g\&.
264 \fB\-\-file=~/mine\fR\&. The shell will expand
266 in the former to your home directory, but most shells keep the tilde in the latter\&. Some of our commands know how to tilde\-expand the option value even when given in the stuck form, but not all of them do\&.
277 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
287 \fB\-\-\fR; the former will not work if you happen to have a file called
300 Many commands allow a long option
302 to be abbreviated only to their unique prefix (e\&.g\&. if there is no other option whose name begins with
303 \fBopt\fR, you may be able to spell
307 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\&.
308 \fB\-\-optimize\fR, to make a short prefix that used to be unique no longer unique\&.
310 .SH "ENHANCED OPTION PARSER"
312 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\&.
314 Here is a list of the facilities provided by this option parser\&.
317 Commands which have the enhanced option parser activated all understand a couple of magic command\-line options:
321 gives a pretty printed usage of the command\&.
328 usage: git describe [<options>] <commit\-ish>*
329 or: git describe [<options>] \-\-dirty
331 \-\-contains find the tag that comes after the commit
332 \-\-debug debug search strategy on stderr
334 \-\-tags use any tag, even unannotated
335 \-\-long always use long format
336 \-\-abbrev[=<n>] use <n> digits to display SHA\-1s
342 Note that some subcommand (e\&.g\&.
344 \fBgrep\fR) may behave differently when there are things on the command line other than
349 without anything else on the command line is meant to consistently give the usage\&.
354 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\&.
356 .SS "Negating options"
358 Options with long option names can be negated by prefixing \fB\-\-no\-\fR\&. For example, \fBgit\fR \fBbranch\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\&.
359 .SS "Aggregating short options"
361 Commands that support the enhanced option parser allow you to aggregate short options\&. This means that you can for example use \fBgit\fR \fBrm\fR \fB\-rf\fR or \fBgit\fR \fBclean\fR \fB\-fdx\fR\&.
362 .SS "Abbreviating long options"
364 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\fR \fBcommit\fR \fB\-\-amen\fR behaves as if you typed \fBgit\fR \fBcommit\fR \fB\-\-amend\fR, but that is true only until a later version of Git introduces another option that shares the same prefix, e\&.g\&. \fBgit\fR \fBcommit\fR \fB\-\-amenity\fR option\&.
365 .SS "Separating argument from the option"
367 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:
373 $ git foo \-\-long\-opt=Arg
374 $ git foo \-\-long\-opt Arg
382 However, this is \fBNOT\fR allowed for switches with an optional value, where the \fIstuck\fR form must be used:
388 $ git describe \-\-abbrev HEAD # correct
389 $ git describe \-\-abbrev=10 HEAD # correct
390 $ git describe \-\-abbrev 10 HEAD # NOT WHAT YOU MEANT
395 .SH "NOTES ON FREQUENTLY CONFUSED OPTIONS"
397 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\&.
409 option is used to ask a command that usually works on files in the working tree to
411 work with the index\&. For example,
413 \fBgrep\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
415 option, it looks for strings in the index\&.
428 option is used to ask a command that usually works on files in the working tree to
430 affect the index\&. For example,
434 usually merges changes recorded in a stash entry to the working tree, but with the
436 option, it also merges changes to the index as well\&.
439 \fBgit\fR \fBapply\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\&.
441 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\&.
443 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\&.
455 \fB\-\-cached\fR, which is used to ask a command to only work on the index, not the working tree\&.
467 is the opposite, to ask a command to work on the working tree only, not the index\&.
478 The two options can be specified together to ask a command to work on both the index and the working tree\&.
482 Part of the \fBgit\fR(1) suite