Documentation / git-clone.txton commit git clone: Add --recursive to automatically checkout (nested) submodules (e7fed18)
   1git-clone(1)
   2============
   3
   4NAME
   5----
   6git-clone - Clone a repository into a new directory
   7
   8
   9SYNOPSIS
  10--------
  11[verse]
  12'git clone' [--template=<template_directory>]
  13          [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
  14          [-o <name>] [-u <upload-pack>] [--reference <repository>]
  15          [--depth <depth>] [--recursive] [--] <repository> [<directory>]
  16
  17DESCRIPTION
  18-----------
  19
  20Clones a repository into a newly created directory, creates
  21remote-tracking branches for each branch in the cloned repository
  22(visible using `git branch -r`), and creates and checks out an initial
  23branch equal to the cloned repository's currently active branch.
  24
  25After the clone, a plain `git fetch` without arguments will update
  26all the remote-tracking branches, and a `git pull` without
  27arguments will in addition merge the remote master branch into the
  28current master branch, if any.
  29
  30This default configuration is achieved by creating references to
  31the remote branch heads under `$GIT_DIR/refs/remotes/origin` and
  32by initializing `remote.origin.url` and `remote.origin.fetch`
  33configuration variables.
  34
  35
  36OPTIONS
  37-------
  38--local::
  39-l::
  40        When the repository to clone from is on a local machine,
  41        this flag bypasses normal "git aware" transport
  42        mechanism and clones the repository by making a copy of
  43        HEAD and everything under objects and refs directories.
  44        The files under `.git/objects/` directory are hardlinked
  45        to save space when possible.  This is now the default when
  46        the source repository is specified with `/path/to/repo`
  47        syntax, so it essentially is a no-op option.  To force
  48        copying instead of hardlinking (which may be desirable
  49        if you are trying to make a back-up of your repository),
  50        but still avoid the usual "git aware" transport
  51        mechanism, `--no-hardlinks` can be used.
  52
  53--no-hardlinks::
  54        Optimize the cloning process from a repository on a
  55        local filesystem by copying files under `.git/objects`
  56        directory.
  57
  58--shared::
  59-s::
  60        When the repository to clone is on the local machine,
  61        instead of using hard links, automatically setup
  62        .git/objects/info/alternates to share the objects
  63        with the source repository.  The resulting repository
  64        starts out without any object of its own.
  65+
  66*NOTE*: this is a possibly dangerous operation; do *not* use
  67it unless you understand what it does. If you clone your
  68repository using this option and then delete branches (or use any
  69other git command that makes any existing commit unreferenced) in the
  70source repository, some objects may become unreferenced (or dangling).
  71These objects may be removed by normal git operations (such as 'git-commit')
  72which automatically call `git gc --auto`. (See linkgit:git-gc[1].)
  73If these objects are removed and were referenced by the cloned repository,
  74then the cloned repository will become corrupt.
  75
  76
  77
  78--reference <repository>::
  79        If the reference repository is on the local machine
  80        automatically setup .git/objects/info/alternates to
  81        obtain objects from the reference repository.  Using
  82        an already existing repository as an alternate will
  83        require fewer objects to be copied from the repository
  84        being cloned, reducing network and local storage costs.
  85+
  86*NOTE*: see NOTE to --shared option.
  87
  88--quiet::
  89-q::
  90        Operate quietly.  This flag is also passed to the `rsync'
  91        command when given.
  92
  93--verbose::
  94-v::
  95        Display the progressbar, even in case the standard output is not
  96        a terminal.
  97
  98--no-checkout::
  99-n::
 100        No checkout of HEAD is performed after the clone is complete.
 101
 102--bare::
 103        Make a 'bare' GIT repository.  That is, instead of
 104        creating `<directory>` and placing the administrative
 105        files in `<directory>/.git`, make the `<directory>`
 106        itself the `$GIT_DIR`. This obviously implies the `-n`
 107        because there is nowhere to check out the working tree.
 108        Also the branch heads at the remote are copied directly
 109        to corresponding local branch heads, without mapping
 110        them to `refs/remotes/origin/`.  When this option is
 111        used, neither remote-tracking branches nor the related
 112        configuration variables are created.
 113
 114--mirror::
 115        Set up a mirror of the remote repository.  This implies --bare.
 116
 117--origin <name>::
 118-o <name>::
 119        Instead of using the remote name 'origin' to keep track
 120        of the upstream repository, use <name>.
 121
 122--upload-pack <upload-pack>::
 123-u <upload-pack>::
 124        When given, and the repository to clone from is accessed
 125        via ssh, this specifies a non-default path for the command
 126        run on the other end.
 127
 128--template=<template_directory>::
 129        Specify the directory from which templates will be used;
 130        if unset the templates are taken from the installation
 131        defined default, typically `/usr/share/git-core/templates`.
 132
 133--depth <depth>::
 134        Create a 'shallow' clone with a history truncated to the
 135        specified number of revisions.  A shallow repository has a
 136        number of limitations (you cannot clone or fetch from
 137        it, nor push from nor into it), but is adequate if you
 138        are only interested in the recent history of a large project
 139        with a long history, and would want to send in fixes
 140        as patches.
 141
 142--recursive::
 143        After the clone is created, initialize all submodules within,
 144        using their default settings. This is equivalent to running
 145        'git submodule update --init --recursive' immediately after
 146        the clone is finished. This option is ignored if the cloned
 147        repository does not have a worktree/checkout (i.e. if any of
 148        `--no-checkout`/`-n`, `--bare`, or `--mirror` is given)
 149
 150<repository>::
 151        The (possibly remote) repository to clone from.  See the
 152        <<URLS,URLS>> section below for more information on specifying
 153        repositories.
 154
 155<directory>::
 156        The name of a new directory to clone into.  The "humanish"
 157        part of the source repository is used if no directory is
 158        explicitly given ("repo" for "/path/to/repo.git" and "foo"
 159        for "host.xz:foo/.git").  Cloning into an existing directory
 160        is only allowed if the directory is empty.
 161
 162:git-clone: 1
 163include::urls.txt[]
 164
 165Examples
 166--------
 167
 168Clone from upstream::
 169+
 170------------
 171$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
 172$ cd my2.6
 173$ make
 174------------
 175
 176
 177Make a local clone that borrows from the current directory, without checking things out::
 178+
 179------------
 180$ git clone -l -s -n . ../copy
 181$ cd ../copy
 182$ git show-branch
 183------------
 184
 185
 186Clone from upstream while borrowing from an existing local directory::
 187+
 188------------
 189$ git clone --reference my2.6 \
 190        git://git.kernel.org/pub/scm/.../linux-2.7 \
 191        my2.7
 192$ cd my2.7
 193------------
 194
 195
 196Create a bare repository to publish your changes to the public::
 197+
 198------------
 199$ git clone --bare -l /home/proj/.git /pub/scm/proj.git
 200------------
 201
 202
 203Create a repository on the kernel.org machine that borrows from Linus::
 204+
 205------------
 206$ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \
 207    /pub/scm/.../me/subsys-2.6.git
 208------------
 209
 210
 211Author
 212------
 213Written by Linus Torvalds <torvalds@osdl.org>
 214
 215
 216Documentation
 217--------------
 218Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 219
 220
 221GIT
 222---
 223Part of the linkgit:git[1] suite