<?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="git-fetch(1)">
<articleinfo>
    <title>git-fetch(1)</title>
        <indexterm>
                <primary>git-fetch(1)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>git-fetch - Download objects and refs from another repository</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<simpara><emphasis>git fetch</emphasis> &lt;options&gt; &lt;repository&gt; &lt;refspec&gt;&#8230;</simpara>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>Fetches named heads or tags from another repository, along with
the objects necessary to complete them.</simpara>
<simpara>The ref names and their object names of fetched refs are stored
in <literal>.git/FETCH_HEAD</literal>.  This information is left for a later merge
operation done by <emphasis>git-merge</emphasis>.</simpara>
<simpara>When &lt;refspec&gt; stores the fetched result in tracking branches,
the tags that point at these branches are automatically
followed.  This is done by first fetching from the remote using
the given &lt;refspec&gt;s, and if the repository has objects that are
pointed by remote tags that it does not yet have, then fetch
those missing tags.  If the other end has tags that point at
branches you are not interested in, you will not get them.</simpara>
</simplesect>
<simplesect id="_options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
-q
</term>
<term>
--quiet
</term>
<listitem>
<simpara>
        Pass --quiet to git-fetch-pack and silence any other internally
        used programs.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-v
</term>
<term>
--verbose
</term>
<listitem>
<simpara>
        Be verbose.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-a
</term>
<term>
--append
</term>
<listitem>
<simpara>
        Append ref names and object names of fetched refs to the
        existing contents of <literal>.git/FETCH_HEAD</literal>.  Without this
        option old data in <literal>.git/FETCH_HEAD</literal> will be overwritten.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--upload-pack &lt;upload-pack&gt;
</term>
<listitem>
<simpara>
        When given, and the repository to fetch from is handled
        by <emphasis>git-fetch-pack</emphasis>, <emphasis>--exec=&lt;upload-pack&gt;</emphasis> is passed to
        the command to specify non-default path for the command
        run on the other end.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-f
</term>
<term>
--force
</term>
<listitem>
<simpara>
        When <emphasis>git-fetch</emphasis> is used with <literal>&lt;rbranch&gt;:&lt;lbranch&gt;</literal>
        refspec, it refuses to update the local branch
        <literal>&lt;lbranch&gt;</literal> unless the remote branch <literal>&lt;rbranch&gt;</literal> it
        fetches is a descendant of <literal>&lt;lbranch&gt;</literal>.  This option
        overrides that check.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-n
</term>
<term>
--no-tags
</term>
<listitem>
<simpara>
        By default, tags that point at objects that are downloaded
        from the remote repository are fetched and stored locally.
        This option disables this automatic tag following.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-t
</term>
<term>
--tags
</term>
<listitem>
<simpara>
        Most of the tags are fetched automatically as branch
        heads are downloaded, but tags that do not point at
        objects reachable from the branch heads that are being
        tracked will not be fetched by this mechanism.  This
        flag lets all tags and their associated objects be
        downloaded.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-k
</term>
<term>
--keep
</term>
<listitem>
<simpara>
        Keep downloaded pack.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-u
</term>
<term>
--update-head-ok
</term>
<listitem>
<simpara>
        By default <emphasis>git-fetch</emphasis> refuses to update the head which
        corresponds to the current branch.  This flag disables the
        check.  This is purely for the internal use for <emphasis>git-pull</emphasis>
        to communicate with <emphasis>git-fetch</emphasis>, and unless you are
        implementing your own Porcelain you are not supposed to
        use it.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--depth=&lt;depth&gt;
</term>
<listitem>
<simpara>
        Deepen the history of a <emphasis>shallow</emphasis> repository created by
        <literal>git clone</literal> with <literal>--depth=&lt;depth&gt;</literal> option (see <xref linkend="git-clone(1)"/>)
        by the specified number of commits.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
&lt;repository&gt;
</term>
<listitem>
<simpara>
        The "remote" repository that is the source of a fetch
        or pull operation.  This parameter can be either a URL
        (see the section <link linkend="URLS">GIT URLS</link> below) or the name
        of a remote (see the section <link linkend="REMOTES">REMOTES</link> below).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
&lt;refspec&gt;
</term>
<listitem>
<simpara>
        The format of a &lt;refspec&gt; parameter is an optional plus
        <literal>&#43;</literal>, followed by the source ref &lt;src&gt;, followed
        by a colon <literal>:</literal>, followed by the destination ref &lt;dst&gt;.
</simpara>
<simpara>The remote ref that matches &lt;src&gt;
is fetched, and if &lt;dst&gt; is not empty string, the local
ref that matches it is fast forwarded using &lt;src&gt;.
If the optional plus <literal>+</literal> is used, the local ref
is updated even if it does not result in a fast forward
update.</simpara>
<note><simpara>If the remote branch from which you want to pull is
modified in non-linear ways such as being rewound and
rebased frequently, then a pull will attempt a merge with
an older version of itself, likely conflict, and fail.
It is under these conditions that you would want to use
the <literal>+</literal> sign to indicate non-fast-forward updates will
be needed.  There is currently no easy way to determine
or declare that a branch will be made available in a
repository with this behavior; the pulling user simply
must know this is the expected usage pattern for a branch.</simpara></note>
<note><simpara>You never do your own development on branches that appear
on the right hand side of a &lt;refspec&gt; colon on <literal>Pull:</literal> lines;
they are to be updated by <emphasis>git-fetch</emphasis>.  If you intend to do
development derived from a remote branch <literal>B</literal>, have a <literal>Pull:</literal>
line to track it (i.e. <literal>Pull: B:remote-B</literal>), and have a separate
branch <literal>my-B</literal> to do your development on top of it.  The latter
is created by <literal>git branch my-B remote-B</literal> (or its equivalent <literal>git
checkout -b my-B remote-B</literal>).  Run <literal>git fetch</literal> to keep track of
the progress of the remote side, and when you see something new
on the remote branch, merge it into your development branch with
<literal>git pull . remote-B</literal>, while you are on <literal>my-B</literal> branch.</simpara></note>
<note><simpara>There is a difference between listing multiple &lt;refspec&gt;
directly on <emphasis>git-pull</emphasis> command line and having multiple
<literal>Pull:</literal> &lt;refspec&gt; lines for a &lt;repository&gt; and running
<emphasis>git-pull</emphasis> command without any explicit &lt;refspec&gt; parameters.
&lt;refspec&gt; listed explicitly on the command line are always
merged into the current branch after fetching.  In other words,
if you list more than one remote refs, you would be making
an Octopus.  While <emphasis>git-pull</emphasis> run without any explicit &lt;refspec&gt;
parameter takes default &lt;refspec&gt;s from <literal>Pull:</literal> lines, it
merges only the first &lt;refspec&gt; found into the current branch,
after fetching all the remote refs.  This is because making an
Octopus from remote refs is rarely done, while keeping track
of multiple remote heads in one-go by fetching more than one
is often useful.</simpara></note>
<simpara>Some short-cut notations are also supported.</simpara>
<itemizedlist>
<listitem>
<simpara>
<literal>tag &lt;tag&gt;</literal> means the same as <literal>refs/tags/&lt;tag&gt;:refs/tags/&lt;tag&gt;</literal>;
  it requests fetching everything up to the given tag.
</simpara>
</listitem>
<listitem>
<simpara>
A parameter &lt;ref&gt; without a colon is equivalent to
  &lt;ref&gt;: when pulling/fetching, so it merges &lt;ref&gt; into the current
  branch without storing the remote branch anywhere locally
</simpara>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_git_urls_anchor_id_urls_xreflabel_urls">
<title>GIT URLS<anchor id="URLS" xreflabel="[URLS]"/></title>
<simpara>One of the following notations can be used
to name the remote repository:</simpara>
<informalexample>
<itemizedlist>
<listitem>
<simpara>
rsync://host.xz/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="http://host.xz&#91;:port&#93;/path/to/repo.git/">http://host.xz&#91;:port&#93;/path/to/repo.git/</ulink>
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="https://host.xz&#91;:port&#93;/path/to/repo.git/">https://host.xz&#91;:port&#93;/path/to/repo.git/</ulink>
</simpara>
</listitem>
<listitem>
<simpara>
git://host.xz&#91;:port&#93;/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
git://host.xz&#91;:port&#93;/~user/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
ssh://&#91;user@&#93;host.xz&#91;:port&#93;/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
ssh://&#91;user@&#93;host.xz/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
ssh://&#91;user@&#93;host.xz/~user/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
ssh://&#91;user@&#93;host.xz/~/path/to/repo.git
</simpara>
</listitem>
</itemizedlist>
</informalexample>
<simpara>SSH is the default transport protocol over the network.  You can
optionally specify which user to log-in as, and an alternate,
scp-like syntax is also supported.  Both syntaxes support
username expansion, as does the native git protocol, but
only the former supports port specification. The following
three are identical to the last three above, respectively:</simpara>
<informalexample>
<itemizedlist>
<listitem>
<simpara>
&#91;user@&#93;host.xz:/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
&#91;user@&#93;host.xz:~user/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
&#91;user@&#93;host.xz:path/to/repo.git
</simpara>
</listitem>
</itemizedlist>
</informalexample>
<simpara>To sync with a local directory, you can use:</simpara>
<informalexample>
<itemizedlist>
<listitem>
<simpara>
/path/to/repo.git/
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="file:///path/to/repo.git/">file:///path/to/repo.git/</ulink>
</simpara>
</listitem>
</itemizedlist>
</informalexample>
<simpara>They are mostly equivalent, except when cloning.  See
<xref linkend="git-clone(1)"/> for details.</simpara>
<simpara>If there are a large number of similarly-named remote repositories and
you want to use a different format for them (such that the URLs you
use will be rewritten into URLs that work), you can create a
configuration section of the form:</simpara>
<literallayout>        [url "&lt;actual url base&gt;"]
                insteadOf = &lt;other url base&gt;</literallayout>
<simpara>For example, with this:</simpara>
<literallayout>        [url "git://git.host.xz/"]
                insteadOf = host.xz:/path/to/
                insteadOf = work:</literallayout>
<simpara>a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
rewritten in any context that takes a URL to be "git://git.host.xz/repo.git".</simpara>
</simplesect>
<simplesect id="_remotes_anchor_id_remotes_xreflabel_remotes">
<title>REMOTES<anchor id="REMOTES" xreflabel="[REMOTES]"/></title>
<simpara>The name of one of the following can be used instead
of a URL as <literal>&lt;repository&gt;</literal> argument:</simpara>
<itemizedlist>
<listitem>
<simpara>
a remote in the git configuration file: <literal>$GIT_DIR/config</literal>,
</simpara>
</listitem>
<listitem>
<simpara>
a file in the <literal>$GIT_DIR/remotes</literal> directory, or
</simpara>
</listitem>
<listitem>
<simpara>
a file in the <literal>$GIT_DIR/branches</literal> directory.
</simpara>
</listitem>
</itemizedlist>
<simpara>All of these also allow you to omit the refspec from the command line
because they each contain a refspec which git will use by default.</simpara>
<simplesect id="_named_remote_in_configuration_file">
<title>Named remote in configuration file</title>
<simpara>You can choose to provide the name of a remote which you had previously
configured using <xref linkend="git-remote(1)"/>, <xref linkend="git-config(1)"/>
or even by a manual edit to the <literal>$GIT_DIR/config</literal> file.  The URL of
this remote will be used to access the repository.  The refspec
of this remote will be used by default when you do
not provide a refspec on the command line.  The entry in the
config file would appear like this:</simpara>
<literallayout>        [remote "&lt;name&gt;"]
                url = &lt;url&gt;
                push = &lt;refspec&gt;
                fetch = &lt;refspec&gt;</literallayout>
</simplesect>
<simplesect id="_named_file_in_literal_git_dir_remotes_literal">
<title>Named file in <literal>$GIT_DIR/remotes</literal></title>
<simpara>You can choose to provide the name of a
file in <literal>$GIT_DIR/remotes</literal>.  The URL
in this file will be used to access the repository.  The refspec
in this file will be used as default when you do not
provide a refspec on the command line.  This file should have the
following format:</simpara>
<literallayout>        URL: one of the above URL format
        Push: &lt;refspec&gt;
        Pull: &lt;refspec&gt;</literallayout>
<simpara><literal>Push:</literal> lines are used by <emphasis>git-push</emphasis> and
<literal>Pull:</literal> lines are used by <emphasis>git-pull</emphasis> and <emphasis>git-fetch</emphasis>.
Multiple <literal>Push:</literal> and <literal>Pull:</literal> lines may
be specified for additional branch mappings.</simpara>
</simplesect>
<simplesect id="_named_file_in_literal_git_dir_branches_literal">
<title>Named file in <literal>$GIT_DIR/branches</literal></title>
<simpara>You can choose to provide the name of a
file in <literal>$GIT_DIR/branches</literal>.
The URL in this file will be used to access the repository.
This file should have the following format:</simpara>
<literallayout>        &lt;url&gt;#&lt;head&gt;</literallayout>
<simpara><literal>&lt;url&gt;</literal> is required; <literal>#&lt;head&gt;</literal> is optional.</simpara>
<simpara>Depending on the operation, git will use one of the following
refspecs, if you don&#8217;t provide one on the command line.
<literal>&lt;branch&gt;</literal> is the name of this file in <literal>$GIT_DIR/branches</literal> and
<literal>&lt;head&gt;</literal> defaults to <literal>master</literal>.</simpara>
<simpara>git fetch uses:</simpara>
<literallayout>        refs/heads/&lt;head&gt;:refs/heads/&lt;branch&gt;</literallayout>
<simpara>git push uses:</simpara>
<literallayout>        HEAD:refs/heads/&lt;head&gt;</literallayout>
</simplesect>
</simplesect>
<simplesect id="_see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-pull(1)"/></simpara>
</simplesect>
<simplesect id="_author">
<title>Author</title>
<simpara>Written by Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt; and
Junio C Hamano &lt;<ulink url="mailto:gitster@pobox.com">gitster@pobox.com</ulink>&gt;</simpara>
</simplesect>
<simplesect id="_documentation">
<title>Documentation</title>
<simpara>Documentation by David Greaves, Junio C Hamano 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>
