blob: 4b8b26b75e63cc56e679d2e2c6d8fd1240010419 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-clone(1)
2============
3
4NAME
5----
Junio C Hamano4ec06712007-06-09 20:39:336git-clone - Clone a repository into a new directory
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamano235a91e2006-01-07 01:13:5811[verse]
Junio C Hamanofce7c7e2008-07-02 03:06:3812'git clone' [--template=<template_directory>]
Junio C Hamanoaf1987f2008-08-03 07:58:1913 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
Junio C Hamano2bd8a742009-12-01 21:16:5914 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
Junio C Hamanof93530e2011-05-25 23:59:5915 [--separate-git-dir <git dir>]
Junio C Hamanoed69a742010-12-01 03:09:2316 [--depth <depth>] [--recursive|--recurse-submodules] [--] <repository>
17 [<directory>]
Junio C Hamano1a4e8412005-12-27 08:17:2318
19DESCRIPTION
20-----------
Junio C Hamano1a4e8412005-12-27 08:17:2321
Junio C Hamano5102d9a2006-12-08 07:23:4622Clones a repository into a newly created directory, creates
23remote-tracking branches for each branch in the cloned repository
Junio C Hamanoc0e55e72009-10-10 00:56:2924(visible using `git branch -r`), and creates and checks out an
25initial branch that is forked from the cloned repository's
26currently active branch.
Junio C Hamano1a4e8412005-12-27 08:17:2327
Junio C Hamano5102d9a2006-12-08 07:23:4628After the clone, a plain `git fetch` without arguments will update
29all the remote-tracking branches, and a `git pull` without
30arguments will in addition merge the remote master branch into the
Junio C Hamano79770b62007-01-07 07:43:5831current master branch, if any.
Junio C Hamano1a4e8412005-12-27 08:17:2332
Junio C Hamano5102d9a2006-12-08 07:23:4633This default configuration is achieved by creating references to
Junio C Hamano4fdccb22010-02-19 09:58:1434the remote branch heads under `refs/remotes/origin` and
Junio C Hamano5102d9a2006-12-08 07:23:4635by initializing `remote.origin.url` and `remote.origin.fetch`
36configuration variables.
Junio C Hamano1a4e8412005-12-27 08:17:2337
Junio C Hamanob288d9e2007-01-02 00:04:1538
Junio C Hamano1a4e8412005-12-27 08:17:2339OPTIONS
40-------
41--local::
42-l::
43When the repository to clone from is on a local machine,
Junio C Hamano621e1232009-10-26 05:16:4744this flag bypasses the normal "git aware" transport
Junio C Hamano1a4e8412005-12-27 08:17:2345mechanism and clones the repository by making a copy of
46HEAD and everything under objects and refs directories.
Junio C Hamanob1d6e882007-08-11 08:30:1647The files under `.git/objects/` directory are hardlinked
48to save space when possible. This is now the default when
49the source repository is specified with `/path/to/repo`
50syntax, so it essentially is a no-op option. To force
51copying instead of hardlinking (which may be desirable
52if you are trying to make a back-up of your repository),
53but still avoid the usual "git aware" transport
54mechanism, `--no-hardlinks` can be used.
55
56--no-hardlinks::
57Optimize the cloning process from a repository on a
58local filesystem by copying files under `.git/objects`
59directory.
Junio C Hamano1a4e8412005-12-27 08:17:2360
61--shared::
62-s::
63When the repository to clone is on the local machine,
64instead of using hard links, automatically setup
Junio C Hamano621e1232009-10-26 05:16:4765`.git/objects/info/alternates` to share the objects
Junio C Hamano1a4e8412005-12-27 08:17:2366with the source repository. The resulting repository
67starts out without any object of its own.
Junio C Hamanoefe3c632008-02-14 00:51:3168+
69*NOTE*: this is a possibly dangerous operation; do *not* use
70it unless you understand what it does. If you clone your
Junio C Hamanoa9aee782008-04-23 16:09:2071repository using this option and then delete branches (or use any
72other git command that makes any existing commit unreferenced) in the
73source repository, some objects may become unreferenced (or dangling).
Junio C Hamano621e1232009-10-26 05:16:4774These objects may be removed by normal git operations (such as `git commit`)
Junio C Hamanofce7c7e2008-07-02 03:06:3875which automatically call `git gc --auto`. (See linkgit:git-gc[1].)
76If these objects are removed and were referenced by the cloned repository,
77then the cloned repository will become corrupt.
Junio C Hamanob9376922009-08-19 00:09:1378+
79Note that running `git repack` without the `-l` option in a repository
80cloned with `-s` will copy objects from the source repository into a pack
81in the cloned repository, removing the disk space savings of `clone -s`.
82It is safe, however, to run `git gc`, which uses the `-l` option by
83default.
84+
85If you want to break the dependency of a repository cloned with `-s` on
86its source repository, you can simply run `git repack -a` to copy all
87objects from the source repository into a pack in the cloned repository.
Junio C Hamano1a4e8412005-12-27 08:17:2388
Junio C Hamanof50bfec2006-04-19 09:44:1289--reference <repository>::
Junio C Hamano35b47ca2009-09-03 18:11:5490If the reference repository is on the local machine,
Junio C Hamano621e1232009-10-26 05:16:4791automatically setup `.git/objects/info/alternates` to
Junio C Hamanof50bfec2006-04-19 09:44:1292obtain objects from the reference repository. Using
93an already existing repository as an alternate will
Junio C Hamano250f03e2007-09-10 01:33:2894require fewer objects to be copied from the repository
Junio C Hamanof50bfec2006-04-19 09:44:1295being cloned, reducing network and local storage costs.
Junio C Hamanoa9aee782008-04-23 16:09:2096+
Junio C Hamano621e1232009-10-26 05:16:4797*NOTE*: see the NOTE for the `--shared` option.
Junio C Hamanof50bfec2006-04-19 09:44:1298
Junio C Hamano1a4e8412005-12-27 08:17:2399--quiet::
100-q::
Junio C Hamano6ce6b6c2010-01-18 01:25:50101Operate quietly. Progress is not reported to the standard
102error stream. This flag is also passed to the `rsync'
Junio C Hamano3db8b412008-07-26 06:45:59103command when given.
Junio C Hamano1a4e8412005-12-27 08:17:23104
Junio C Hamano7d06a8a2008-10-20 05:42:33105--verbose::
106-v::
Junio C Hamanoea90ab32010-03-15 20:32:55107Run verbosely. Does not affect the reporting of progress status
108to the standard error stream.
Junio C Hamano6ce6b6c2010-01-18 01:25:50109
110--progress::
111Progress status is reported on the standard error stream
112by default when it is attached to a terminal, unless -q
113is specified. This flag forces progress status even if the
114standard error stream is not directed to a terminal.
Junio C Hamano7d06a8a2008-10-20 05:42:33115
Junio C Hamano1e6e0062007-07-13 05:33:25116--no-checkout::
Junio C Hamano1a4e8412005-12-27 08:17:23117-n::
118No checkout of HEAD is performed after the clone is complete.
119
Junio C Hamanoe663a7a2006-01-25 12:37:28120--bare::
121Make a 'bare' GIT repository. That is, instead of
Junio C Hamano38064d52006-01-15 10:13:49122creating `<directory>` and placing the administrative
123files in `<directory>/.git`, make the `<directory>`
Junio C Hamano9f292e72006-11-24 11:37:29124itself the `$GIT_DIR`. This obviously implies the `-n`
125because there is nowhere to check out the working tree.
126Also the branch heads at the remote are copied directly
127to corresponding local branch heads, without mapping
128them to `refs/remotes/origin/`. When this option is
Junio C Hamanod3361ad2007-01-01 03:20:24129used, neither remote-tracking branches nor the related
130configuration variables are created.
Junio C Hamano38064d52006-01-15 10:13:49131
Junio C Hamanoaf1987f2008-08-03 07:58:19132--mirror::
Junio C Hamano657fd8a2010-10-07 00:01:24133Set up a mirror of the source repository. This implies `--bare`.
134Compared to `--bare`, `--mirror` not only maps local branches of the
135source to local branches of the target, it maps all refs (including
Junio C Hamano97bcb482010-11-25 03:16:07136remote-tracking branches, notes etc.) and sets up a refspec configuration such
Junio C Hamano657fd8a2010-10-07 00:01:24137that all these refs are overwritten by a `git remote update` in the
138target repository.
Junio C Hamanoaf1987f2008-08-03 07:58:19139
Junio C Hamanodcc22ee2006-11-03 02:40:13140--origin <name>::
Junio C Hamano1a4e8412005-12-27 08:17:23141-o <name>::
Junio C Hamano621e1232009-10-26 05:16:47142Instead of using the remote name `origin` to keep track
143of the upstream repository, use `<name>`.
Junio C Hamano1a4e8412005-12-27 08:17:23144
Junio C Hamanoc28068f2009-09-08 00:55:23145--branch <name>::
146-b <name>::
147Instead of pointing the newly created HEAD to the branch pointed
Junio C Hamano621e1232009-10-26 05:16:47148to by the cloned repository's HEAD, point to `<name>` branch
Junio C Hamanoc28068f2009-09-08 00:55:23149instead. In a non-bare repository, this is the branch that will
150be checked out.
151
Junio C Hamano1a4e8412005-12-27 08:17:23152--upload-pack <upload-pack>::
153-u <upload-pack>::
Junio C Hamano3db8b412008-07-26 06:45:59154When given, and the repository to clone from is accessed
155via ssh, this specifies a non-default path for the command
Junio C Hamano1a4e8412005-12-27 08:17:23156run on the other end.
157
Junio C Hamanof31d9f52006-05-28 20:58:09158--template=<template_directory>::
159Specify the directory from which templates will be used;
Junio C Hamanocaa712a2010-03-11 01:17:35160(See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
Junio C Hamanof31d9f52006-05-28 20:58:09161
Junio C Hamano708376e2011-07-19 20:02:13162--config <key>=<value>::
163-c <key>=<value>::
164Set a configuration variable in the newly-created repository;
165this takes effect immediately after the repository is
166initialized, but before the remote history is fetched or any
167files checked out. The key is in the same format as expected by
168linkgit:git-config[1] (e.g., `core.eol=true`). If multiple
169values are given for the same key, each value will be written to
170the config file. This makes it safe, for example, to add
171additional fetch refspecs to the origin remote.
172
Junio C Hamano0bbd4672007-02-20 04:52:14173--depth <depth>::
Junio C Hamanob288d9e2007-01-02 00:04:15174Create a 'shallow' clone with a history truncated to the
Junio C Hamano1c708832007-11-02 02:47:50175specified number of revisions. A shallow repository has a
Junio C Hamanob288d9e2007-01-02 00:04:15176number of limitations (you cannot clone or fetch from
177it, nor push from nor into it), but is adequate if you
Junio C Hamano1c708832007-11-02 02:47:50178are only interested in the recent history of a large project
179with a long history, and would want to send in fixes
Junio C Hamanob288d9e2007-01-02 00:04:15180as patches.
181
Junio C Hamano0e066b92009-08-28 01:08:41182--recursive::
Junio C Hamanoed69a742010-12-01 03:09:23183--recurse-submodules::
Junio C Hamano0e066b92009-08-28 01:08:41184After the clone is created, initialize all submodules within,
185using their default settings. This is equivalent to running
Junio C Hamano621e1232009-10-26 05:16:47186`git submodule update --init --recursive` immediately after
Junio C Hamano0e066b92009-08-28 01:08:41187the clone is finished. This option is ignored if the cloned
188repository does not have a worktree/checkout (i.e. if any of
189`--no-checkout`/`-n`, `--bare`, or `--mirror` is given)
190
Junio C Hamanoa03ac862011-04-02 04:32:29191--separate-git-dir=<git dir>::
192Instead of placing the cloned repository where it is supposed
193to be, place the cloned repository at the specified directory,
194then make a filesytem-agnostic git symbolic link to there.
195The result is git repository can be separated from working
196tree.
197
198
Junio C Hamano1a4e8412005-12-27 08:17:23199<repository>::
Junio C Hamano330aae62007-07-06 17:01:58200The (possibly remote) repository to clone from. See the
201<<URLS,URLS>> section below for more information on specifying
202repositories.
Junio C Hamano1a4e8412005-12-27 08:17:23203
204<directory>::
Junio C Hamano8db10ef2006-06-09 04:31:57205The name of a new directory to clone into. The "humanish"
Junio C Hamano1a4e8412005-12-27 08:17:23206part of the source repository is used if no directory is
Junio C Hamano621e1232009-10-26 05:16:47207explicitly given (`repo` for `/path/to/repo.git` and `foo`
208for `host.xz:foo/.git`). Cloning into an existing directory
Junio C Hamano89bdb3b2009-05-10 06:48:14209is only allowed if the directory is empty.
Junio C Hamano1a4e8412005-12-27 08:17:23210
Junio C Hamano63777e22007-11-17 20:52:16211:git-clone: 1
Junio C Hamano330aae62007-07-06 17:01:58212include::urls.txt[]
213
Junio C Hamano1a4e8412005-12-27 08:17:23214Examples
Junio C Hamano1bb569e2006-05-05 23:14:25215--------
Junio C Hamano1a4e8412005-12-27 08:17:23216
Junio C Hamano9ccf6642010-03-22 01:47:35217* Clone from upstream:
Junio C Hamano1a4e8412005-12-27 08:17:23218+
219------------
220$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
221$ cd my2.6
222$ make
223------------
224
225
Junio C Hamano9ccf6642010-03-22 01:47:35226* Make a local clone that borrows from the current directory, without checking things out:
Junio C Hamano1a4e8412005-12-27 08:17:23227+
228------------
229$ git clone -l -s -n . ../copy
Junio C Hamano8638c922007-05-12 20:50:08230$ cd ../copy
Junio C Hamano1a4e8412005-12-27 08:17:23231$ git show-branch
232------------
233
Junio C Hamano38064d52006-01-15 10:13:49234
Junio C Hamano9ccf6642010-03-22 01:47:35235* Clone from upstream while borrowing from an existing local directory:
Junio C Hamanof50bfec2006-04-19 09:44:12236+
237------------
238$ git clone --reference my2.6 \
239git://git.kernel.org/pub/scm/.../linux-2.7 \
240my2.7
241$ cd my2.7
242------------
243
244
Junio C Hamano9ccf6642010-03-22 01:47:35245* Create a bare repository to publish your changes to the public:
Junio C Hamano38064d52006-01-15 10:13:49246+
247------------
Junio C Hamanoe663a7a2006-01-25 12:37:28248$ git clone --bare -l /home/proj/.git /pub/scm/proj.git
Junio C Hamano38064d52006-01-15 10:13:49249------------
250
251
Junio C Hamano9ccf6642010-03-22 01:47:35252* Create a repository on the kernel.org machine that borrows from Linus:
Junio C Hamano38064d52006-01-15 10:13:49253+
254------------
Junio C Hamanoe663a7a2006-01-25 12:37:28255$ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \
Junio C Hamano38064d52006-01-15 10:13:49256 /pub/scm/.../me/subsys-2.6.git
257------------
258
Junio C Hamano1a4e8412005-12-27 08:17:23259GIT
260---
Junio C Hamanof7c042d2008-06-06 22:50:53261Part of the linkgit:git[1] suite