blob: dfe7d8372723c7a4970b8a7100764d1becc7f830 [file] [log] [blame]
Junio C Hamano2fbcd212008-05-14 22:26:071gitcli(7)
Junio C Hamanof556fc22007-12-23 08:16:382=========
3
4NAME
5----
Junio C Hamanoe1aeb5e2014-06-06 19:16:296gitcli - Git command-line interface and conventions
Junio C Hamanof556fc22007-12-23 08:16:387
8SYNOPSIS
9--------
10gitcli
11
12
13DESCRIPTION
14-----------
15
Junio C Hamano076ffcc2013-02-06 05:13:2116This manual describes the convention used throughout Git CLI.
Junio C Hamanoc4fec202008-06-28 10:07:2417
18Many commands take revisions (most often "commits", but sometimes
19"tree-ish", depending on the context and command) and paths as their
20arguments. Here are the rules:
21
22 * Revisions come first and then paths.
23 E.g. in `git diff v1.0 v2.0 arch/x86 include/asm-x86`,
24 `v1.0` and `v2.0` are revisions and `arch/x86` and `include/asm-x86`
25 are paths.
26
27 * When an argument can be misunderstood as either a revision or a path,
Junio C Hamanob76a6862012-05-02 22:02:4628 they can be disambiguated by placing `--` between them.
29 E.g. `git diff -- HEAD` is, "I have a file called HEAD in my work
Junio C Hamanoc4fec202008-06-28 10:07:2430 tree. Please show changes between the version I staged in the index
Junio C Hamano826f5c42014-02-07 20:33:3031 and what I have in the work tree for that file", not "show difference
Junio C Hamanoc4fec202008-06-28 10:07:2432 between the HEAD commit and the work tree as a whole". You can say
Junio C Hamanob76a6862012-05-02 22:02:4633 `git diff HEAD --` to ask for the latter.
Junio C Hamanoc4fec202008-06-28 10:07:2434
Junio C Hamano076ffcc2013-02-06 05:13:2135 * Without disambiguating `--`, Git makes a reasonable guess, but errors
Junio C Hamanoc4fec202008-06-28 10:07:2436 out and asking you to disambiguate when ambiguous. E.g. if you have a
37 file called HEAD in your work tree, `git diff HEAD` is ambiguous, and
Junio C Hamanob76a6862012-05-02 22:02:4638 you have to say either `git diff HEAD --` or `git diff -- HEAD` to
Junio C Hamanoc4fec202008-06-28 10:07:2439 disambiguate.
Junio C Hamano693e7092012-09-12 22:56:5340+
Junio C Hamanoc4fec202008-06-28 10:07:2441When writing a script that is expected to handle random user-input, it is
42a good practice to make it explicit which arguments are which by placing
Junio C Hamanob76a6862012-05-02 22:02:4643disambiguating `--` at appropriate places.
Junio C Hamanoc4fec202008-06-28 10:07:2444
Junio C Hamano693e7092012-09-12 22:56:5345 * Many commands allow wildcards in paths, but you need to protect
46 them from getting globbed by the shell. These two mean different
47 things:
48+
49--------------------------------
50$ git checkout -- *.c
51$ git checkout -- \*.c
52--------------------------------
53+
54The former lets your shell expand the fileglob, and you are asking
55the dot-C files in your working tree to be overwritten with the version
56in the index. The latter passes the `*.c` to Git, and you are asking
57the paths in the index that match the pattern to be checked out to your
58working tree. After running `git add hello.c; rm hello.c`, you will _not_
59see `hello.c` in your working tree with the former, but with the latter
60you will.
61
Junio C Hamano238ce9c2013-10-23 21:56:3862 * Just as the filesystem '.' (period) refers to the current directory,
63 using a '.' as a repository name in Git (a dot-repository) is a relative
64 path and means your current repository.
65
Junio C Hamanoc4fec202008-06-28 10:07:2466Here are the rules regarding the "flags" that you should follow when you are
Junio C Hamano076ffcc2013-02-06 05:13:2167scripting Git:
Junio C Hamanof556fc22007-12-23 08:16:3868
Junio C Hamanoe1aeb5e2014-06-06 19:16:2969 * it's preferred to use the non-dashed form of Git commands, which means that
Junio C Hamanoea82cff2009-03-18 01:54:4870 you should prefer `git foo` to `git-foo`.
Junio C Hamanof556fc22007-12-23 08:16:3871
Junio C Hamanoea82cff2009-03-18 01:54:4872 * splitting short options to separate words (prefer `git foo -a -b`
73 to `git foo -ab`, the latter may not even work).
Junio C Hamanof556fc22007-12-23 08:16:3874
Junio C Hamanoe1aeb5e2014-06-06 19:16:2975 * when a command-line option takes an argument, use the 'stuck' form. In
Junio C Hamanoea82cff2009-03-18 01:54:4876 other words, write `git foo -oArg` instead of `git foo -o Arg` for short
77 options, and `git foo --long-opt=Arg` instead of `git foo --long-opt Arg`
Junio C Hamanof556fc22007-12-23 08:16:3878 for long options. An option that takes optional option-argument must be
Junio C Hamanof079f702013-12-06 23:43:1879 written in the 'stuck' form.
Junio C Hamanof556fc22007-12-23 08:16:3880
81 * when you give a revision parameter to a command, make sure the parameter is
82 not ambiguous with a name of a file in the work tree. E.g. do not write
Junio C Hamanoea82cff2009-03-18 01:54:4883 `git log -1 HEAD` but write `git log -1 HEAD --`; the former will not work
Junio C Hamanof556fc22007-12-23 08:16:3884 if you happen to have a file called `HEAD` in the work tree.
85
Junio C Hamanob73af6c2013-12-03 22:07:1186 * many commands allow a long option `--option` to be abbreviated
Junio C Hamanod0316112012-08-22 19:55:2987 only to their unique prefix (e.g. if there is no other option
Junio C Hamanob73af6c2013-12-03 22:07:1188 whose name begins with `opt`, you may be able to spell `--opt` to
89 invoke the `--option` flag), but you should fully spell them out
Junio C Hamanod0316112012-08-22 19:55:2990 when writing your scripts; later versions of Git may introduce a
Junio C Hamanob73af6c2013-12-03 22:07:1191 new option whose name shares the same prefix, e.g. `--optimize`,
Junio C Hamanod0316112012-08-22 19:55:2992 to make a short prefix that used to be unique no longer unique.
93
Junio C Hamanof556fc22007-12-23 08:16:3894
Junio C Hamanoc4fec202008-06-28 10:07:2495ENHANCED OPTION PARSER
96----------------------
Junio C Hamano076ffcc2013-02-06 05:13:2197From the Git 1.5.4 series and further, many Git commands (not all of them at the
Junio C Hamanof556fc22007-12-23 08:16:3898time of the writing though) come with an enhanced option parser.
99
Junio C Hamano6631a092012-10-10 22:50:57100Here is a list of the facilities provided by this option parser.
Junio C Hamanof556fc22007-12-23 08:16:38101
102
103Magic Options
104~~~~~~~~~~~~~
105Commands which have the enhanced option parser activated all understand a
Junio C Hamanoe1aeb5e2014-06-06 19:16:29106couple of magic command-line options:
Junio C Hamanof556fc22007-12-23 08:16:38107
108-h::
109gives a pretty printed usage of the command.
110+
111---------------------------------------------
112$ git describe -h
Junio C Hamanoe6f28d02013-09-17 21:34:00113usage: git describe [options] <commit-ish>*
Junio C Hamano947ab822013-03-19 23:07:29114 or: git describe [options] --dirty
Junio C Hamanof556fc22007-12-23 08:16:38115
116 --contains find the tag that comes after the commit
117 --debug debug search strategy on stderr
Junio C Hamano947ab822013-03-19 23:07:29118 --all use any ref
119 --tags use any tag, even unannotated
120 --long always use long format
121 --abbrev[=<n>] use <n> digits to display SHA-1s
Junio C Hamanof556fc22007-12-23 08:16:38122---------------------------------------------
123
124--help-all::
Junio C Hamano076ffcc2013-02-06 05:13:21125Some Git commands take options that are only used for plumbing or that
Junio C Hamanof556fc22007-12-23 08:16:38126are deprecated, and such options are hidden from the default usage. This
127option gives the full list of options.
128
129
130Negating options
131~~~~~~~~~~~~~~~~
Junio C Hamanoea82cff2009-03-18 01:54:48132Options with long option names can be negated by prefixing `--no-`. For
133example, `git branch` has the option `--track` which is 'on' by default. You
134can use `--no-track` to override that behaviour. The same goes for `--color`
135and `--no-color`.
Junio C Hamanof556fc22007-12-23 08:16:38136
137
138Aggregating short options
139~~~~~~~~~~~~~~~~~~~~~~~~~
140Commands that support the enhanced option parser allow you to aggregate short
Junio C Hamanoea82cff2009-03-18 01:54:48141options. This means that you can for example use `git rm -rf` or
142`git clean -fdx`.
Junio C Hamanof556fc22007-12-23 08:16:38143
144
Junio C Hamano6631a092012-10-10 22:50:57145Abbreviating long options
146~~~~~~~~~~~~~~~~~~~~~~~~~
147Commands that support the enhanced option parser accepts unique
148prefix of a long option as if it is fully spelled out, but use this
149with a caution. For example, `git commit --amen` behaves as if you
150typed `git commit --amend`, but that is true only until a later version
151of Git introduces another option that shares the same prefix,
Junio C Hamanob73af6c2013-12-03 22:07:11152e.g. `git commit --amenity` option.
Junio C Hamano6631a092012-10-10 22:50:57153
154
Junio C Hamanof556fc22007-12-23 08:16:38155Separating argument from the option
156~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157You can write the mandatory option parameter to an option as a separate
158word on the command line. That means that all the following uses work:
159
160----------------------------
161$ git foo --long-opt=Arg
162$ git foo --long-opt Arg
163$ git foo -oArg
164$ git foo -o Arg
165----------------------------
166
Junio C Hamano4e272312008-01-08 09:13:21167However, this is *NOT* allowed for switches with an optional value, where the
Junio C Hamanof079f702013-12-06 23:43:18168'stuck' form must be used:
Junio C Hamanof556fc22007-12-23 08:16:38169----------------------------
170$ git describe --abbrev HEAD # correct
171$ git describe --abbrev=10 HEAD # correct
172$ git describe --abbrev 10 HEAD # NOT WHAT YOU MEANT
173----------------------------
174
175
Junio C Hamanofce7c7e2008-07-02 03:06:38176NOTES ON FREQUENTLY CONFUSED OPTIONS
177------------------------------------
178
179Many commands that can work on files in the working tree
180and/or in the index can take `--cached` and/or `--index`
181options. Sometimes people incorrectly think that, because
182the index was originally called cache, these two are
183synonyms. They are *not* -- these two options mean very
184different things.
185
186 * The `--cached` option is used to ask a command that
187 usually works on files in the working tree to *only* work
188 with the index. For example, `git grep`, when used
189 without a commit to specify from which commit to look for
190 strings in, usually works on files in the working tree,
191 but with the `--cached` option, it looks for strings in
192 the index.
193
194 * The `--index` option is used to ask a command that
195 usually works on files in the working tree to *also*
196 affect the index. For example, `git stash apply` usually
197 merges changes recorded in a stash to the working tree,
198 but with the `--index` option, it also merges changes to
199 the index as well.
200
201`git apply` command can be used with `--cached` and
202`--index` (but not at the same time). Usually the command
203only affects the files in the working tree, but with
204`--index`, it patches both the files and their index
205entries, and with `--cached`, it modifies only the index
206entries.
207
208See also http://marc.info/?l=git&m=116563135620359 and
209http://marc.info/?l=git&m=119150393620273 for further
210information.
211
Junio C Hamanof556fc22007-12-23 08:16:38212GIT
213---
Junio C Hamanof7c042d2008-06-06 22:50:53214Part of the linkgit:git[1] suite