<?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-clone(1)">
<articleinfo>
    <title>git-clone(1)</title>
        <indexterm>
                <primary>git-clone(1)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>git-clone - Clone a repository into a new directory</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git clone</emphasis> [--template=&lt;template_directory&gt;]
          [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
          [-o &lt;name&gt;] [-u &lt;upload-pack&gt;] [--reference &lt;repository&gt;]
          [--depth &lt;depth&gt;] [--] &lt;repository&gt; [&lt;directory&gt;]</literallayout>
</blockquote>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>Clones a repository into a newly created directory, creates
remote-tracking branches for each branch in the cloned repository
(visible using <literal>git branch -r</literal>), and creates and checks out an initial
branch equal to the cloned repository&#8217;s currently active branch.</simpara>
<simpara>After the clone, a plain <literal>git fetch</literal> without arguments will update
all the remote-tracking branches, and a <literal>git pull</literal> without
arguments will in addition merge the remote master branch into the
current master branch, if any.</simpara>
<simpara>This default configuration is achieved by creating references to
the remote branch heads under <literal>$GIT_DIR/refs/remotes/origin</literal> and
by initializing <literal>remote.origin.url</literal> and <literal>remote.origin.fetch</literal>
configuration variables.</simpara>
</simplesect>
<simplesect id="_options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
--local
</term>
<term>
-l
</term>
<listitem>
<simpara>
        When the repository to clone from is on a local machine,
        this flag bypasses normal "git aware" transport
        mechanism and clones the repository by making a copy of
        HEAD and everything under objects and refs directories.
        The files under <literal>.git/objects/</literal> directory are hardlinked
        to save space when possible.  This is now the default when
        the source repository is specified with <literal>/path/to/repo</literal>
        syntax, so it essentially is a no-op option.  To force
        copying instead of hardlinking (which may be desirable
        if you are trying to make a back-up of your repository),
        but still avoid the usual "git aware" transport
        mechanism, <literal>--no-hardlinks</literal> can be used.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-hardlinks
</term>
<listitem>
<simpara>
        Optimize the cloning process from a repository on a
        local filesystem by copying files under <literal>.git/objects</literal>
        directory.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--shared
</term>
<term>
-s
</term>
<listitem>
<simpara>
        When the repository to clone is on the local machine,
        instead of using hard links, automatically setup
        .git/objects/info/alternates to share the objects
        with the source repository.  The resulting repository
        starts out without any object of its own.
</simpara>
<simpara><emphasis role="strong">NOTE</emphasis>: this is a possibly dangerous operation; do <emphasis role="strong">not</emphasis> use
it unless you understand what it does. If you clone your
repository using this option and then delete branches (or use any
other git command that makes any existing commit unreferenced) in the
source repository, some objects may become unreferenced (or dangling).
These objects may be removed by normal git operations (such as <emphasis>git-commit</emphasis>)
which automatically call <literal>git gc --auto</literal>. (See <xref linkend="git-gc(1)"/>.)
If these objects are removed and were referenced by the cloned repository,
then the cloned repository will become corrupt.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--reference &lt;repository&gt;
</term>
<listitem>
<simpara>
        If the reference repository is on the local machine
        automatically setup .git/objects/info/alternates to
        obtain objects from the reference repository.  Using
        an already existing repository as an alternate will
        require fewer objects to be copied from the repository
        being cloned, reducing network and local storage costs.
</simpara>
<simpara><emphasis role="strong">NOTE</emphasis>: see NOTE to --shared option.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--quiet
</term>
<term>
-q
</term>
<listitem>
<simpara>
        Operate quietly.  This flag is also passed to the &#8216;rsync&#8217;
        command when given.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--verbose
</term>
<term>
-v
</term>
<listitem>
<simpara>
        Display the progressbar, even in case the standard output is not
        a terminal.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-checkout
</term>
<term>
-n
</term>
<listitem>
<simpara>
        No checkout of HEAD is performed after the clone is complete.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--bare
</term>
<listitem>
<simpara>
        Make a <emphasis>bare</emphasis> GIT repository.  That is, instead of
        creating <literal>&lt;directory&gt;</literal> and placing the administrative
        files in <literal>&lt;directory&gt;/.git</literal>, make the <literal>&lt;directory&gt;</literal>
        itself the <literal>$GIT_DIR</literal>. This obviously implies the <literal>-n</literal>
        because there is nowhere to check out the working tree.
        Also the branch heads at the remote are copied directly
        to corresponding local branch heads, without mapping
        them to <literal>refs/remotes/origin/</literal>.  When this option is
        used, neither remote-tracking branches nor the related
        configuration variables are created.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--mirror
</term>
<listitem>
<simpara>
        Set up a mirror of the remote repository.  This implies --bare.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--origin &lt;name&gt;
</term>
<term>
-o &lt;name&gt;
</term>
<listitem>
<simpara>
        Instead of using the remote name <emphasis>origin</emphasis> to keep track
        of the upstream repository, use &lt;name&gt; instead.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--upload-pack &lt;upload-pack&gt;
</term>
<term>
-u &lt;upload-pack&gt;
</term>
<listitem>
<simpara>
        When given, and the repository to clone from is accessed
        via ssh, this specifies a non-default path for the command
        run on the other end.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--template=&lt;template_directory&gt;
</term>
<listitem>
<simpara>
        Specify the directory from which templates will be used;
        if unset the templates are taken from the installation
        defined default, typically <literal>/usr/share/git-core/templates</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--depth &lt;depth&gt;
</term>
<listitem>
<simpara>
        Create a <emphasis>shallow</emphasis> clone with a history truncated to the
        specified number of revisions.  A shallow repository has a
        number of limitations (you cannot clone or fetch from
        it, nor push from nor into it), but is adequate if you
        are only interested in the recent history of a large project
        with a long history, and would want to send in fixes
        as patches.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
&lt;repository&gt;
</term>
<listitem>
<simpara>
        The (possibly remote) repository to clone from.  See the
        <link linkend="URLS">URLS</link> section below for more information on specifying
        repositories.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
&lt;directory&gt;
</term>
<listitem>
<simpara>
        The name of a new directory to clone into.  The "humanish"
        part of the source repository is used if no directory is
        explicitly given ("repo" for "/path/to/repo.git" and "foo"
        for "host.xz:foo/.git").  Cloning into an existing directory
        is not allowed.
</simpara>
</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 equivalent, except the former implies --local option.</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="_examples">
<title>Examples</title>
<variablelist>
<varlistentry>
<term>
Clone from upstream
</term>
<listitem>
<literallayout>$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
$ cd my2.6
$ make</literallayout>
</listitem>
</varlistentry>
<varlistentry>
<term>
Make a local clone that borrows from the current directory, without checking things out
</term>
<listitem>
<literallayout>$ git clone -l -s -n . ../copy
$ cd ../copy
$ git show-branch</literallayout>
</listitem>
</varlistentry>
<varlistentry>
<term>
Clone from upstream while borrowing from an existing local directory
</term>
<listitem>
<literallayout>$ git clone --reference my2.6 \
        git://git.kernel.org/pub/scm/.../linux-2.7 \
        my2.7
$ cd my2.7</literallayout>
</listitem>
</varlistentry>
<varlistentry>
<term>
Create a bare repository to publish your changes to the public
</term>
<listitem>
<literallayout>$ git clone --bare -l /home/proj/.git /pub/scm/proj.git</literallayout>
</listitem>
</varlistentry>
<varlistentry>
<term>
Create a repository on the kernel.org machine that borrows from Linus
</term>
<listitem>
<literallayout>$ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \
    /pub/scm/.../me/subsys-2.6.git</literallayout>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_author">
<title>Author</title>
<simpara>Written by Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt;</simpara>
</simplesect>
<simplesect id="_documentation">
<title>Documentation</title>
<simpara>Documentation by 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>
