<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<article lang="en" id="gitcli(7)">
<articleinfo>
    <title>gitcli(7)</title>
        <indexterm>
                <primary>gitcli(7)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>gitcli - git command line interface and conventions</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<simpara>gitcli</simpara>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>This manual describes the convention used throughout git CLI.</simpara>
<simpara>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:</simpara>
<itemizedlist>
<listitem>
<simpara>
Revisions come first and then paths.
   E.g. in <literal>git diff v1.0 v2.0 arch/x86 include/asm-x86</literal>,
   <literal>v1.0</literal> and <literal>v2.0</literal> are revisions and <literal>arch/x86</literal> and <literal>include/asm-x86</literal>
   are paths.
</simpara>
</listitem>
<listitem>
<simpara>
When an argument can be misunderstood as either a revision or a path,
   they can be disambiguated by placing <literal>--</literal> between them.
   E.g. <literal>git diff -- HEAD</literal> 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
   <literal>git diff HEAD --</literal> to ask for the latter.
</simpara>
</listitem>
<listitem>
<simpara>
Without disambiguating <literal>--</literal>, 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, <literal>git diff HEAD</literal> is ambiguous, and
   you have to say either <literal>git diff HEAD --</literal> or <literal>git diff -- HEAD</literal> to
   disambiguate.
</simpara>
</listitem>
</itemizedlist>
<simpara>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 <literal>--</literal> at appropriate places.</simpara>
<simpara>Here are the rules regarding the "flags" that you should follow when you are
scripting git:</simpara>
<itemizedlist>
<listitem>
<simpara>
it&#8217;s preferred to use the non dashed form of git commands, which means that
   you should prefer <literal>"git foo"</literal> to <literal>"git-foo"</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
splitting short options to separate words (prefer <literal>"git foo -a -b"</literal>
   to <literal>"git foo -ab"</literal>, the latter may not even work).
</simpara>
</listitem>
<listitem>
<simpara>
when a command line option takes an argument, use the <emphasis>sticked</emphasis> form.  In
   other words, write <literal>"git foo -oArg"</literal> instead of <literal>"git foo -o Arg"</literal> for short
   options, and <literal>"git foo --long-opt=Arg"</literal> instead of <literal>"git foo --long-opt Arg"</literal>
   for long options.  An option that takes optional option-argument must be
   written in the <emphasis>sticked</emphasis> form.
</simpara>
</listitem>
<listitem>
<simpara>
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
   <literal>"git log -1 HEAD"</literal> but write <literal>"git log -1 HEAD --"</literal>; the former will not work
   if you happen to have a file called <literal>HEAD</literal> in the work tree.
</simpara>
</listitem>
</itemizedlist>
</simplesect>
<simplesect id="_enhanced_option_parser">
<title>ENHANCED OPTION PARSER</title>
<simpara>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.</simpara>
<simpara>Here is an exhaustive list of the facilities provided by this option parser.</simpara>
<simplesect id="_magic_options">
<title>Magic Options</title>
<simpara>Commands which have the enhanced option parser activated all understand a
couple of magic command line options:</simpara>
<variablelist>
<varlistentry>
<term>
-h
</term>
<listitem>
<simpara>
        gives a pretty printed usage of the command.
</simpara>
<literallayout>$ git describe -h
usage: git-describe [options] &lt;committish&gt;*

    --contains            find the tag that comes after the commit
    --debug               debug search strategy on stderr
    --all                 use any ref in .git/refs
    --tags                use any tag in .git/refs/tags
    --abbrev [&lt;n&gt;]        use &lt;n&gt; digits to display SHA-1s
    --candidates &lt;n&gt;      consider &lt;n&gt; most recent tags (default: 10)</literallayout>
</listitem>
</varlistentry>
<varlistentry>
<term>
--help-all
</term>
<listitem>
<simpara>
        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.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_negating_options">
<title>Negating options</title>
<simpara>Options with long option names can be negated by prefixing <literal>"--no-"</literal>. For
example, <literal>"git branch"</literal> has the option <literal>"--track"</literal> which is <emphasis>on</emphasis> by default. You
can use <literal>"--no-track"</literal> to override that behaviour. The same goes for <literal>"--color"</literal>
and <literal>"--no-color"</literal>.</simpara>
</simplesect>
<simplesect id="_aggregating_short_options">
<title>Aggregating short options</title>
<simpara>Commands that support the enhanced option parser allow you to aggregate short
options. This means that you can for example use <literal>"git rm -rf"</literal> or
<literal>"git clean -fdx"</literal>.</simpara>
</simplesect>
<simplesect id="_separating_argument_from_the_option">
<title>Separating argument from the option</title>
<simpara>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:</simpara>
<literallayout>$ git foo --long-opt=Arg
$ git foo --long-opt Arg
$ git foo -oArg
$ git foo -o Arg</literallayout>
<simpara>However, this is <emphasis role="strong">NOT</emphasis> allowed for switches with an optional value, where the
<emphasis>sticked</emphasis> form must be used:</simpara>
<literallayout>$ git describe --abbrev HEAD     # correct
$ git describe --abbrev=10 HEAD  # correct
$ git describe --abbrev 10 HEAD  # NOT WHAT YOU MEANT</literallayout>
</simplesect>
</simplesect>
<simplesect id="_notes_on_frequently_confused_options">
<title>NOTES ON FREQUENTLY CONFUSED OPTIONS</title>
<simpara>Many commands that can work on files in the working tree
and/or in the index can take <literal>--cached</literal> and/or <literal>--index</literal>
options.  Sometimes people incorrectly think that, because
the index was originally called cache, these two are
synonyms.  They are <emphasis role="strong">not</emphasis>&#8201;&#8212;&#8201;these two options mean very
different things.</simpara>
<itemizedlist>
<listitem>
<simpara>
The <literal>--cached</literal> option is used to ask a command that
   usually works on files in the working tree to <emphasis role="strong">only</emphasis> work
   with the index.  For example, <literal>git grep</literal>, 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 <literal>--cached</literal> option, it looks for strings in
   the index.
</simpara>
</listitem>
<listitem>
<simpara>
The <literal>--index</literal> option is used to ask a command that
   usually works on files in the working tree to <emphasis role="strong">also</emphasis>
   affect the index.  For example, <literal>git stash apply</literal> usually
   merges changes recorded in a stash to the working tree,
   but with the <literal>--index</literal> option, it also merges changes to
   the index as well.
</simpara>
</listitem>
</itemizedlist>
<simpara><literal>git apply</literal> command can be used with <literal>--cached</literal> and
<literal>--index</literal> (but not at the same time).  Usually the command
only affects the files in the working tree, but with
<literal>--index</literal>, it patches both the files and their index
entries, and with <literal>--cached</literal>, it modifies only the index
entries.</simpara>
<simpara>See also <ulink url="http://marc.info/?l=git&amp;m=116563135620359">http://marc.info/?l=git&amp;m=116563135620359</ulink> and
<ulink url="http://marc.info/?l=git&amp;m=119150393620273">http://marc.info/?l=git&amp;m=119150393620273</ulink> for further
information.</simpara>
</simplesect>
<simplesect id="_documentation">
<title>Documentation</title>
<simpara>Documentation by Pierre Habouzit and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>
</simplesect>
<simplesect id="_git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
</simplesect>
</article>
