blob: c1ddd4c2cc78e078a0849fc8fb82f8de0aa7fc9b [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 Hamanob5be0522012-01-29 22:20:1916 [--depth <depth>] [--[no-]single-branch]
17 [--recursive|--recurse-submodules] [--] <repository>
Junio C Hamanoed69a742010-12-01 03:09:2318 [<directory>]
Junio C Hamano1a4e8412005-12-27 08:17:2319
20DESCRIPTION
21-----------
Junio C Hamano1a4e8412005-12-27 08:17:2322
Junio C Hamano5102d9a2006-12-08 07:23:4623Clones a repository into a newly created directory, creates
24remote-tracking branches for each branch in the cloned repository
Junio C Hamanoc0e55e72009-10-10 00:56:2925(visible using `git branch -r`), and creates and checks out an
26initial branch that is forked from the cloned repository's
27currently active branch.
Junio C Hamano1a4e8412005-12-27 08:17:2328
Junio C Hamano5102d9a2006-12-08 07:23:4629After the clone, a plain `git fetch` without arguments will update
30all the remote-tracking branches, and a `git pull` without
31arguments will in addition merge the remote master branch into the
Junio C Hamano79770b62007-01-07 07:43:5832current master branch, if any.
Junio C Hamano1a4e8412005-12-27 08:17:2333
Junio C Hamano5102d9a2006-12-08 07:23:4634This default configuration is achieved by creating references to
Junio C Hamano4fdccb22010-02-19 09:58:1435the remote branch heads under `refs/remotes/origin` and
Junio C Hamano5102d9a2006-12-08 07:23:4636by initializing `remote.origin.url` and `remote.origin.fetch`
37configuration variables.
Junio C Hamano1a4e8412005-12-27 08:17:2338
Junio C Hamanob288d9e2007-01-02 00:04:1539
Junio C Hamano1a4e8412005-12-27 08:17:2340OPTIONS
41-------
42--local::
43-l::
44When the repository to clone from is on a local machine,
Junio C Hamano621e1232009-10-26 05:16:4745this flag bypasses the normal "git aware" transport
Junio C Hamano1a4e8412005-12-27 08:17:2346mechanism and clones the repository by making a copy of
47HEAD and everything under objects and refs directories.
Junio C Hamanob1d6e882007-08-11 08:30:1648The files under `.git/objects/` directory are hardlinked
Junio C Hamano7f2b3cb2012-06-22 22:42:3949to save space when possible.
50+
51If the repository is specified as a local path (e.g., `/path/to/repo`),
52this is the default, and --local is essentially a no-op. If the
53repository is specified as a URL, then this flag is ignored (and we
54never use the local optimizations). Specifying `--no-local` will
55override the default when `/path/to/repo` is given, using the regular
56git transport instead.
57+
58To force copying instead of hardlinking (which may be desirable if you
59are trying to make a back-up of your repository), but still avoid the
60usual "git aware" transport mechanism, `--no-hardlinks` can be used.
Junio C Hamanob1d6e882007-08-11 08:30:1661
62--no-hardlinks::
63Optimize the cloning process from a repository on a
64local filesystem by copying files under `.git/objects`
65directory.
Junio C Hamano1a4e8412005-12-27 08:17:2366
67--shared::
68-s::
69When the repository to clone is on the local machine,
70instead of using hard links, automatically setup
Junio C Hamano621e1232009-10-26 05:16:4771`.git/objects/info/alternates` to share the objects
Junio C Hamano1a4e8412005-12-27 08:17:2372with the source repository. The resulting repository
73starts out without any object of its own.
Junio C Hamanoefe3c632008-02-14 00:51:3174+
75*NOTE*: this is a possibly dangerous operation; do *not* use
76it unless you understand what it does. If you clone your
Junio C Hamanoa9aee782008-04-23 16:09:2077repository using this option and then delete branches (or use any
78other git command that makes any existing commit unreferenced) in the
79source repository, some objects may become unreferenced (or dangling).
Junio C Hamano621e1232009-10-26 05:16:4780These objects may be removed by normal git operations (such as `git commit`)
Junio C Hamanofce7c7e2008-07-02 03:06:3881which automatically call `git gc --auto`. (See linkgit:git-gc[1].)
82If these objects are removed and were referenced by the cloned repository,
83then the cloned repository will become corrupt.
Junio C Hamanob9376922009-08-19 00:09:1384+
85Note that running `git repack` without the `-l` option in a repository
86cloned with `-s` will copy objects from the source repository into a pack
87in the cloned repository, removing the disk space savings of `clone -s`.
88It is safe, however, to run `git gc`, which uses the `-l` option by
89default.
90+
91If you want to break the dependency of a repository cloned with `-s` on
92its source repository, you can simply run `git repack -a` to copy all
93objects from the source repository into a pack in the cloned repository.
Junio C Hamano1a4e8412005-12-27 08:17:2394
Junio C Hamanof50bfec2006-04-19 09:44:1295--reference <repository>::
Junio C Hamano35b47ca2009-09-03 18:11:5496If the reference repository is on the local machine,
Junio C Hamano621e1232009-10-26 05:16:4797automatically setup `.git/objects/info/alternates` to
Junio C Hamanof50bfec2006-04-19 09:44:1298obtain objects from the reference repository. Using
99an already existing repository as an alternate will
Junio C Hamano250f03e2007-09-10 01:33:28100require fewer objects to be copied from the repository
Junio C Hamanof50bfec2006-04-19 09:44:12101being cloned, reducing network and local storage costs.
Junio C Hamanoa9aee782008-04-23 16:09:20102+
Junio C Hamano621e1232009-10-26 05:16:47103*NOTE*: see the NOTE for the `--shared` option.
Junio C Hamanof50bfec2006-04-19 09:44:12104
Junio C Hamano1a4e8412005-12-27 08:17:23105--quiet::
106-q::
Junio C Hamano6ce6b6c2010-01-18 01:25:50107Operate quietly. Progress is not reported to the standard
108error stream. This flag is also passed to the `rsync'
Junio C Hamano3db8b412008-07-26 06:45:59109command when given.
Junio C Hamano1a4e8412005-12-27 08:17:23110
Junio C Hamano7d06a8a2008-10-20 05:42:33111--verbose::
112-v::
Junio C Hamanoea90ab32010-03-15 20:32:55113Run verbosely. Does not affect the reporting of progress status
114to the standard error stream.
Junio C Hamano6ce6b6c2010-01-18 01:25:50115
116--progress::
117Progress status is reported on the standard error stream
118by default when it is attached to a terminal, unless -q
119is specified. This flag forces progress status even if the
120standard error stream is not directed to a terminal.
Junio C Hamano7d06a8a2008-10-20 05:42:33121
Junio C Hamano1e6e0062007-07-13 05:33:25122--no-checkout::
Junio C Hamano1a4e8412005-12-27 08:17:23123-n::
124No checkout of HEAD is performed after the clone is complete.
125
Junio C Hamanoe663a7a2006-01-25 12:37:28126--bare::
127Make a 'bare' GIT repository. That is, instead of
Junio C Hamano38064d52006-01-15 10:13:49128creating `<directory>` and placing the administrative
129files in `<directory>/.git`, make the `<directory>`
Junio C Hamano9f292e72006-11-24 11:37:29130itself the `$GIT_DIR`. This obviously implies the `-n`
131because there is nowhere to check out the working tree.
132Also the branch heads at the remote are copied directly
133to corresponding local branch heads, without mapping
134them to `refs/remotes/origin/`. When this option is
Junio C Hamanod3361ad2007-01-01 03:20:24135used, neither remote-tracking branches nor the related
136configuration variables are created.
Junio C Hamano38064d52006-01-15 10:13:49137
Junio C Hamanoaf1987f2008-08-03 07:58:19138--mirror::
Junio C Hamano657fd8a2010-10-07 00:01:24139Set up a mirror of the source repository. This implies `--bare`.
140Compared to `--bare`, `--mirror` not only maps local branches of the
141source to local branches of the target, it maps all refs (including
Junio C Hamano97bcb482010-11-25 03:16:07142remote-tracking branches, notes etc.) and sets up a refspec configuration such
Junio C Hamano657fd8a2010-10-07 00:01:24143that all these refs are overwritten by a `git remote update` in the
144target repository.
Junio C Hamanoaf1987f2008-08-03 07:58:19145
Junio C Hamanodcc22ee2006-11-03 02:40:13146--origin <name>::
Junio C Hamano1a4e8412005-12-27 08:17:23147-o <name>::
Junio C Hamano621e1232009-10-26 05:16:47148Instead of using the remote name `origin` to keep track
149of the upstream repository, use `<name>`.
Junio C Hamano1a4e8412005-12-27 08:17:23150
Junio C Hamanoc28068f2009-09-08 00:55:23151--branch <name>::
152-b <name>::
153Instead of pointing the newly created HEAD to the branch pointed
Junio C Hamano621e1232009-10-26 05:16:47154to by the cloned repository's HEAD, point to `<name>` branch
Junio C Hamano56bcc4f2012-02-01 07:21:46155instead. `--branch` can also take tags and treat them like
156detached HEAD. In a non-bare repository, this is the branch
157that will be checked out.
Junio C Hamanoc28068f2009-09-08 00:55:23158
Junio C Hamano1a4e8412005-12-27 08:17:23159--upload-pack <upload-pack>::
160-u <upload-pack>::
Junio C Hamano3db8b412008-07-26 06:45:59161When given, and the repository to clone from is accessed
162via ssh, this specifies a non-default path for the command
Junio C Hamano1a4e8412005-12-27 08:17:23163run on the other end.
164
Junio C Hamanof31d9f52006-05-28 20:58:09165--template=<template_directory>::
166Specify the directory from which templates will be used;
Junio C Hamanocaa712a2010-03-11 01:17:35167(See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
Junio C Hamanof31d9f52006-05-28 20:58:09168
Junio C Hamano708376e2011-07-19 20:02:13169--config <key>=<value>::
170-c <key>=<value>::
171Set a configuration variable in the newly-created repository;
172this takes effect immediately after the repository is
173initialized, but before the remote history is fetched or any
174files checked out. The key is in the same format as expected by
175linkgit:git-config[1] (e.g., `core.eol=true`). If multiple
176values are given for the same key, each value will be written to
177the config file. This makes it safe, for example, to add
178additional fetch refspecs to the origin remote.
179
Junio C Hamano0bbd4672007-02-20 04:52:14180--depth <depth>::
Junio C Hamanob288d9e2007-01-02 00:04:15181Create a 'shallow' clone with a history truncated to the
Junio C Hamano1c708832007-11-02 02:47:50182specified number of revisions. A shallow repository has a
Junio C Hamanob288d9e2007-01-02 00:04:15183number of limitations (you cannot clone or fetch from
184it, nor push from nor into it), but is adequate if you
Junio C Hamano1c708832007-11-02 02:47:50185are only interested in the recent history of a large project
186with a long history, and would want to send in fixes
Junio C Hamanob288d9e2007-01-02 00:04:15187as patches.
188
Junio C Hamanob5be0522012-01-29 22:20:19189--single-branch::
190Clone only the history leading to the tip of a single branch,
191either specified by the `--branch` option or the primary
192branch remote's `HEAD` points at. When creating a shallow
193clone with the `--depth` option, this is the default, unless
194`--no-single-branch` is given to fetch the histories near the
195tips of all branches.
196
Junio C Hamano0e066b92009-08-28 01:08:41197--recursive::
Junio C Hamanoed69a742010-12-01 03:09:23198--recurse-submodules::
Junio C Hamano0e066b92009-08-28 01:08:41199After the clone is created, initialize all submodules within,
200using their default settings. This is equivalent to running
Junio C Hamano621e1232009-10-26 05:16:47201`git submodule update --init --recursive` immediately after
Junio C Hamano0e066b92009-08-28 01:08:41202the clone is finished. This option is ignored if the cloned
203repository does not have a worktree/checkout (i.e. if any of
204`--no-checkout`/`-n`, `--bare`, or `--mirror` is given)
205
Junio C Hamanoa03ac862011-04-02 04:32:29206--separate-git-dir=<git dir>::
207Instead of placing the cloned repository where it is supposed
208to be, place the cloned repository at the specified directory,
209then make a filesytem-agnostic git symbolic link to there.
210The result is git repository can be separated from working
211tree.
212
213
Junio C Hamano1a4e8412005-12-27 08:17:23214<repository>::
Junio C Hamano330aae62007-07-06 17:01:58215The (possibly remote) repository to clone from. See the
216<<URLS,URLS>> section below for more information on specifying
217repositories.
Junio C Hamano1a4e8412005-12-27 08:17:23218
219<directory>::
Junio C Hamano8db10ef2006-06-09 04:31:57220The name of a new directory to clone into. The "humanish"
Junio C Hamano1a4e8412005-12-27 08:17:23221part of the source repository is used if no directory is
Junio C Hamano621e1232009-10-26 05:16:47222explicitly given (`repo` for `/path/to/repo.git` and `foo`
223for `host.xz:foo/.git`). Cloning into an existing directory
Junio C Hamano89bdb3b2009-05-10 06:48:14224is only allowed if the directory is empty.
Junio C Hamano1a4e8412005-12-27 08:17:23225
Junio C Hamano63777e22007-11-17 20:52:16226:git-clone: 1
Junio C Hamano330aae62007-07-06 17:01:58227include::urls.txt[]
228
Junio C Hamano1a4e8412005-12-27 08:17:23229Examples
Junio C Hamano1bb569e2006-05-05 23:14:25230--------
Junio C Hamano1a4e8412005-12-27 08:17:23231
Junio C Hamano9ccf6642010-03-22 01:47:35232* Clone from upstream:
Junio C Hamano1a4e8412005-12-27 08:17:23233+
234------------
235$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
236$ cd my2.6
237$ make
238------------
239
240
Junio C Hamano9ccf6642010-03-22 01:47:35241* Make a local clone that borrows from the current directory, without checking things out:
Junio C Hamano1a4e8412005-12-27 08:17:23242+
243------------
244$ git clone -l -s -n . ../copy
Junio C Hamano8638c922007-05-12 20:50:08245$ cd ../copy
Junio C Hamano1a4e8412005-12-27 08:17:23246$ git show-branch
247------------
248
Junio C Hamano38064d52006-01-15 10:13:49249
Junio C Hamano9ccf6642010-03-22 01:47:35250* Clone from upstream while borrowing from an existing local directory:
Junio C Hamanof50bfec2006-04-19 09:44:12251+
252------------
253$ git clone --reference my2.6 \
254git://git.kernel.org/pub/scm/.../linux-2.7 \
255my2.7
256$ cd my2.7
257------------
258
259
Junio C Hamano9ccf6642010-03-22 01:47:35260* Create a bare repository to publish your changes to the public:
Junio C Hamano38064d52006-01-15 10:13:49261+
262------------
Junio C Hamanoe663a7a2006-01-25 12:37:28263$ git clone --bare -l /home/proj/.git /pub/scm/proj.git
Junio C Hamano38064d52006-01-15 10:13:49264------------
265
266
Junio C Hamano9ccf6642010-03-22 01:47:35267* Create a repository on the kernel.org machine that borrows from Linus:
Junio C Hamano38064d52006-01-15 10:13:49268+
269------------
Junio C Hamanoe663a7a2006-01-25 12:37:28270$ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \
Junio C Hamano38064d52006-01-15 10:13:49271 /pub/scm/.../me/subsys-2.6.git
272------------
273
Junio C Hamano1a4e8412005-12-27 08:17:23274GIT
275---
Junio C Hamanof7c042d2008-06-06 22:50:53276Part of the linkgit:git[1] suite