blob: 984d194934fb84253e7f6b763256e09e2ddd8e91 [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 Hamano59a32b02021-12-10 22:53: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 Hamano59a32b02021-12-10 22:53:3815 [--dissociate] [--separate-git-dir <git-dir>]
Junio C Hamanod5176902017-05-16 04:30:5616 [--depth <depth>] [--[no-]single-branch] [--no-tags]
Junio C Hamano047135e2017-12-19 21:57:5417 [--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
Junio C Hamanoddc69f12021-04-08 21:50:1118 [--[no-]remote-submodules] [--jobs <n>] [--sparse] [--[no-]reject-shallow]
Junio C Hamano67bf2242020-04-22 21:41:4419 [--filter=<filter>] [--] <repository>
Junio C Hamano73c64862019-06-18 03:24:2020 [<directory>]
Junio C Hamano1a4e8412005-12-27 08:17:2321
22DESCRIPTION
23-----------
Junio C Hamano1a4e8412005-12-27 08:17:2324
Junio C Hamano5102d9a2006-12-08 07:23:4625Clones a repository into a newly created directory, creates
26remote-tracking branches for each branch in the cloned repository
Junio C Hamano0906e982019-07-12 20:33:4327(visible using `git branch --remotes`), and creates and checks out an
Junio C Hamanoc0e55e72009-10-10 00:56:2928initial branch that is forked from the cloned repository's
29currently active branch.
Junio C Hamano1a4e8412005-12-27 08:17:2330
Junio C Hamano5102d9a2006-12-08 07:23:4631After the clone, a plain `git fetch` without arguments will update
32all the remote-tracking branches, and a `git pull` without
33arguments will in addition merge the remote master branch into the
Junio C Hamano6a8a8482012-10-01 20:59:4134current master branch, if any (this is untrue when "--single-branch"
35is given; see below).
Junio C Hamano1a4e8412005-12-27 08:17:2336
Junio C Hamano5102d9a2006-12-08 07:23:4637This default configuration is achieved by creating references to
Junio C Hamano4fdccb22010-02-19 09:58:1438the remote branch heads under `refs/remotes/origin` and
Junio C Hamano5102d9a2006-12-08 07:23:4639by initializing `remote.origin.url` and `remote.origin.fetch`
40configuration variables.
Junio C Hamano1a4e8412005-12-27 08:17:2341
Junio C Hamanob288d9e2007-01-02 00:04:1542
Junio C Hamano1a4e8412005-12-27 08:17:2343OPTIONS
44-------
Junio C Hamano1a4e8412005-12-27 08:17:2345-l::
Junio C Hamano0906e982019-07-12 20:33:4346--local::
Junio C Hamano1a4e8412005-12-27 08:17:2347When the repository to clone from is on a local machine,
Junio C Hamano076ffcc2013-02-06 05:13:2148this flag bypasses the normal "Git aware" transport
Junio C Hamano1a4e8412005-12-27 08:17:2349mechanism and clones the repository by making a copy of
50HEAD and everything under objects and refs directories.
Junio C Hamanob1d6e882007-08-11 08:30:1651The files under `.git/objects/` directory are hardlinked
Junio C Hamano7f2b3cb2012-06-22 22:42:3952to save space when possible.
53+
54If the repository is specified as a local path (e.g., `/path/to/repo`),
55this is the default, and --local is essentially a no-op. If the
56repository is specified as a URL, then this flag is ignored (and we
57never use the local optimizations). Specifying `--no-local` will
58override the default when `/path/to/repo` is given, using the regular
Junio C Hamano076ffcc2013-02-06 05:13:2159Git transport instead.
Junio C Hamano7887f9b2021-01-25 23:32:3360+
61*NOTE*: this operation can race with concurrent modification to the
62source repository, similar to running `cp -r src dst` while modifying
63`src`.
Junio C Hamanob1d6e882007-08-11 08:30:1664
65--no-hardlinks::
Junio C Hamano5b3533d2014-02-27 23:07:1566Force the cloning process from a repository on a local
67filesystem to copy the files under the `.git/objects`
68directory instead of using hardlinks. This may be desirable
69if you are trying to make a back-up of your repository.
Junio C Hamano1a4e8412005-12-27 08:17:2370
Junio C Hamano1a4e8412005-12-27 08:17:2371-s::
Junio C Hamano0906e982019-07-12 20:33:4372--shared::
Junio C Hamano1a4e8412005-12-27 08:17:2373When the repository to clone is on the local machine,
74instead of using hard links, automatically setup
Junio C Hamano621e1232009-10-26 05:16:4775`.git/objects/info/alternates` to share the objects
Junio C Hamano1a4e8412005-12-27 08:17:2376with the source repository. The resulting repository
77starts out without any object of its own.
Junio C Hamanoefe3c632008-02-14 00:51:3178+
79*NOTE*: this is a possibly dangerous operation; do *not* use
80it unless you understand what it does. If you clone your
Junio C Hamanoa9aee782008-04-23 16:09:2081repository using this option and then delete branches (or use any
Junio C Hamano076ffcc2013-02-06 05:13:2182other Git command that makes any existing commit unreferenced) in the
Junio C Hamanoa9aee782008-04-23 16:09:2083source repository, some objects may become unreferenced (or dangling).
Junio C Hamano076ffcc2013-02-06 05:13:2184These objects may be removed by normal Git operations (such as `git commit`)
Junio C Hamanoc562f6d2020-09-25 22:50:1285which automatically call `git maintenance run --auto`. (See
86linkgit:git-maintenance[1].) If these objects are removed and were referenced
87by the cloned repository, then the cloned repository will become corrupt.
Junio C Hamanob9376922009-08-19 00:09:1388+
Junio C Hamano0906e982019-07-12 20:33:4389Note that running `git repack` without the `--local` option in a repository
90cloned with `--shared` will copy objects from the source repository into a pack
91in the cloned repository, removing the disk space savings of `clone --shared`.
92It is safe, however, to run `git gc`, which uses the `--local` option by
Junio C Hamanob9376922009-08-19 00:09:1393default.
94+
Junio C Hamano0906e982019-07-12 20:33:4395If you want to break the dependency of a repository cloned with `--shared` on
Junio C Hamanob9376922009-08-19 00:09:1396its source repository, you can simply run `git repack -a` to copy all
97objects from the source repository into a pack in the cloned repository.
Junio C Hamano1a4e8412005-12-27 08:17:2398
Junio C Hamanocd451662016-09-13 00:54:0999--reference[-if-able] <repository>::
Junio C Hamano35b47ca2009-09-03 18:11:54100If the reference repository is on the local machine,
Junio C Hamano621e1232009-10-26 05:16:47101automatically setup `.git/objects/info/alternates` to
Junio C Hamanof50bfec2006-04-19 09:44:12102obtain objects from the reference repository. Using
103an already existing repository as an alternate will
Junio C Hamano250f03e2007-09-10 01:33:28104require fewer objects to be copied from the repository
Junio C Hamanof50bfec2006-04-19 09:44:12105being cloned, reducing network and local storage costs.
Junio C Hamanocd451662016-09-13 00:54:09106When using the `--reference-if-able`, a non existing
107directory is skipped with a warning instead of aborting
108the clone.
Junio C Hamanoa9aee782008-04-23 16:09:20109+
Junio C Hamanoc9394b22015-01-07 22:45:48110*NOTE*: see the NOTE for the `--shared` option, and also the
111`--dissociate` option.
112
113--dissociate::
114Borrow the objects from reference repositories specified
115with the `--reference` options only to reduce network
Junio C Hamano448d1322015-10-30 21:57:54116transfer, and stop borrowing from them after a clone is made
117by making necessary local copies of borrowed objects. This
118option can also be used when cloning locally from a
119repository that already borrows objects from another
120repository--the new repository will borrow objects from the
121same repository, and this option can be used to stop the
122borrowing.
Junio C Hamanof50bfec2006-04-19 09:44:12123
Junio C Hamano1a4e8412005-12-27 08:17:23124-q::
Junio C Hamano0906e982019-07-12 20:33:43125--quiet::
Junio C Hamano6ce6b6c2010-01-18 01:25:50126Operate quietly. Progress is not reported to the standard
Junio C Hamanof85ef632016-02-17 22:31:06127error stream.
Junio C Hamano1a4e8412005-12-27 08:17:23128
Junio C Hamano7d06a8a2008-10-20 05:42:33129-v::
Junio C Hamano0906e982019-07-12 20:33:43130--verbose::
Junio C Hamanoea90ab32010-03-15 20:32:55131Run verbosely. Does not affect the reporting of progress status
132to the standard error stream.
Junio C Hamano6ce6b6c2010-01-18 01:25:50133
134--progress::
135Progress status is reported on the standard error stream
Junio C Hamano0906e982019-07-12 20:33:43136by default when it is attached to a terminal, unless `--quiet`
Junio C Hamano6ce6b6c2010-01-18 01:25:50137is specified. This flag forces progress status even if the
138standard error stream is not directed to a terminal.
Junio C Hamano7d06a8a2008-10-20 05:42:33139
Junio C Hamanod1063b12019-05-08 17:18:07140--server-option=<option>::
141Transmit the given string to the server when communicating using
142protocol version 2. The given string must not contain a NUL or LF
143character. The server's handling of server options, including
144unknown ones, is server-specific.
145When multiple `--server-option=<option>` are given, they are all
146sent to the other side in the order listed on the command line.
147
Junio C Hamano1a4e8412005-12-27 08:17:23148-n::
Junio C Hamano0906e982019-07-12 20:33:43149--no-checkout::
Junio C Hamano1a4e8412005-12-27 08:17:23150No checkout of HEAD is performed after the clone is complete.
151
Junio C Hamanoddc69f12021-04-08 21:50:11152--[no-]reject-shallow::
153Fail if the source repository is a shallow repository.
154The 'clone.rejectShallow' configuration variable can be used to
155specify the default.
156
Junio C Hamanoe663a7a2006-01-25 12:37:28157--bare::
Junio C Hamano076ffcc2013-02-06 05:13:21158Make a 'bare' Git repository. That is, instead of
Junio C Hamano38064d52006-01-15 10:13:49159creating `<directory>` and placing the administrative
160files in `<directory>/.git`, make the `<directory>`
Junio C Hamano0906e982019-07-12 20:33:43161itself the `$GIT_DIR`. This obviously implies the `--no-checkout`
Junio C Hamano9f292e72006-11-24 11:37:29162because there is nowhere to check out the working tree.
163Also the branch heads at the remote are copied directly
164to corresponding local branch heads, without mapping
165them to `refs/remotes/origin/`. When this option is
Junio C Hamanod3361ad2007-01-01 03:20:24166used, neither remote-tracking branches nor the related
167configuration variables are created.
Junio C Hamano38064d52006-01-15 10:13:49168
Junio C Hamano2f5a9892019-12-25 21:12:55169--sparse::
Junio C Hamano05fe8d12022-01-04 00:50:38170Employ a sparse-checkout, with only files in the toplevel
171directory initially being present. The
172linkgit:git-sparse-checkout[1] command can be used to grow the
173working directory as needed.
Junio C Hamano2f5a9892019-12-25 21:12:55174
Junio C Hamano67bf2242020-04-22 21:41:44175--filter=<filter-spec>::
176Use the partial clone feature and request that the server sends
177a subset of reachable objects according to a given object filter.
178When using `--filter`, the supplied `<filter-spec>` is used for
179the partial clone filter. For example, `--filter=blob:none` will
180filter out all blobs (file contents) until needed by Git. Also,
181`--filter=blob:limit=<size>` will filter out all blobs of size
182at least `<size>`. For more details on filter specifications, see
183the `--filter` option in linkgit:git-rev-list[1].
184
Junio C Hamanoaf1987f2008-08-03 07:58:19185--mirror::
Junio C Hamano657fd8a2010-10-07 00:01:24186Set up a mirror of the source repository. This implies `--bare`.
187Compared to `--bare`, `--mirror` not only maps local branches of the
188source to local branches of the target, it maps all refs (including
Junio C Hamano97bcb482010-11-25 03:16:07189remote-tracking branches, notes etc.) and sets up a refspec configuration such
Junio C Hamano657fd8a2010-10-07 00:01:24190that all these refs are overwritten by a `git remote update` in the
191target repository.
Junio C Hamanoaf1987f2008-08-03 07:58:19192
Junio C Hamano1a4e8412005-12-27 08:17:23193-o <name>::
Junio C Hamano0906e982019-07-12 20:33:43194--origin <name>::
Junio C Hamano6a3d6652020-10-27 23:01:14195Instead of using the remote name `origin` to keep track of the upstream
196repository, use `<name>`. Overrides `clone.defaultRemoteName` from the
197config.
Junio C Hamano1a4e8412005-12-27 08:17:23198
Junio C Hamanoc28068f2009-09-08 00:55:23199-b <name>::
Junio C Hamano0906e982019-07-12 20:33:43200--branch <name>::
Junio C Hamanoc28068f2009-09-08 00:55:23201Instead of pointing the newly created HEAD to the branch pointed
Junio C Hamano621e1232009-10-26 05:16:47202to by the cloned repository's HEAD, point to `<name>` branch
Junio C Hamano6a8a8482012-10-01 20:59:41203instead. In a non-bare repository, this is the branch that will
204be checked out.
205`--branch` can also take tags and detaches the HEAD at that commit
206in the resulting repository.
Junio C Hamanoc28068f2009-09-08 00:55:23207
Junio C Hamano1a4e8412005-12-27 08:17:23208-u <upload-pack>::
Junio C Hamano0906e982019-07-12 20:33:43209--upload-pack <upload-pack>::
Junio C Hamano3db8b412008-07-26 06:45:59210When given, and the repository to clone from is accessed
211via ssh, this specifies a non-default path for the command
Junio C Hamano1a4e8412005-12-27 08:17:23212run on the other end.
213
Junio C Hamano59a32b02021-12-10 22:53:38214--template=<template-directory>::
Junio C Hamanof31d9f52006-05-28 20:58:09215Specify the directory from which templates will be used;
Junio C Hamanocaa712a2010-03-11 01:17:35216(See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
Junio C Hamanof31d9f52006-05-28 20:58:09217
Junio C Hamano708376e2011-07-19 20:02:13218-c <key>=<value>::
Junio C Hamano0906e982019-07-12 20:33:43219--config <key>=<value>::
Junio C Hamano708376e2011-07-19 20:02:13220Set a configuration variable in the newly-created repository;
221this takes effect immediately after the repository is
222initialized, but before the remote history is fetched or any
223files checked out. The key is in the same format as expected by
224linkgit:git-config[1] (e.g., `core.eol=true`). If multiple
225values are given for the same key, each value will be written to
226the config file. This makes it safe, for example, to add
227additional fetch refspecs to the origin remote.
Junio C Hamanode48f452019-01-04 22:31:57228+
229Due to limitations of the current implementation, some configuration
230variables do not take effect until after the initial fetch and checkout.
231Configuration variables known to not take effect are:
232`remote.<name>.mirror` and `remote.<name>.tagOpt`. Use the
233corresponding `--mirror` and `--no-tags` options instead.
Junio C Hamano708376e2011-07-19 20:02:13234
Junio C Hamano0bbd4672007-02-20 04:52:14235--depth <depth>::
Junio C Hamanob288d9e2007-01-02 00:04:15236Create a 'shallow' clone with a history truncated to the
Junio C Hamano4e6ba272016-01-20 23:23:19237specified number of commits. Implies `--single-branch` unless
238`--no-single-branch` is given to fetch the histories near the
Junio C Hamanoc6c919b2016-07-06 21:34:15239tips of all branches. If you want to clone submodules shallowly,
240also pass `--shallow-submodules`.
Junio C Hamanob288d9e2007-01-02 00:04:15241
Junio C Hamano20829a42016-10-10 23:24:44242--shallow-since=<date>::
243Create a shallow clone with a history after the specified time.
244
245--shallow-exclude=<revision>::
246Create a shallow clone with a history, excluding commits
247reachable from a specified remote branch or tag. This option
248can be specified multiple times.
249
Junio C Hamano3d1b5a12013-05-17 23:34:02250--[no-]single-branch::
Junio C Hamanob5be0522012-01-29 22:20:19251Clone only the history leading to the tip of a single branch,
252either specified by the `--branch` option or the primary
Junio C Hamano4e6ba272016-01-20 23:23:19253branch remote's `HEAD` points at.
Junio C Hamano6a8a8482012-10-01 20:59:41254Further fetches into the resulting repository will only update the
Junio C Hamanoa1295452012-11-13 22:32:04255remote-tracking branch for the branch this option was used for the
Junio C Hamano6a8a8482012-10-01 20:59:41256initial cloning. If the HEAD at the remote did not point at any
Junio C Hamanoa1295452012-11-13 22:32:04257branch when `--single-branch` clone was made, no remote-tracking
Junio C Hamano6a8a8482012-10-01 20:59:41258branch is created.
Junio C Hamanob5be0522012-01-29 22:20:19259
Junio C Hamanod5176902017-05-16 04:30:56260--no-tags::
261Don't clone any tags, and set
262`remote.<remote>.tagOpt=--no-tags` in the config, ensuring
263that future `git pull` and `git fetch` operations won't follow
264any tags. Subsequent explicit tag fetches will still work,
265(see linkgit:git-fetch[1]).
266+
267Can be used in conjunction with `--single-branch` to clone and
268maintain a branch with no references other than a single cloned
269branch. This is useful e.g. to maintain minimal clones of the default
270branch of some repository for search indexing.
271
Junio C Hamanoa8911782020-07-07 05:35:57272--recurse-submodules[=<pathspec>]::
Junio C Hamanodc8d0c32017-03-30 23:00:21273After the clone is created, initialize and clone submodules
274within based on the provided pathspec. If no pathspec is
275provided, all submodules are initialized and cloned.
Junio C Hamano047135e2017-12-19 21:57:54276This option can be given multiple times for pathspecs consisting
277of multiple entries. The resulting clone has `submodule.active` set to
Junio C Hamanodc8d0c32017-03-30 23:00:21278the provided pathspec, or "." (meaning all submodules) if no
Junio C Hamano047135e2017-12-19 21:57:54279pathspec is provided.
280+
281Submodules are initialized and cloned using their default settings. This is
282equivalent to running
283`git submodule update --init --recursive <pathspec>` immediately after
284the clone is finished. This option is ignored if the cloned repository does
285not have a worktree/checkout (i.e. if any of `--no-checkout`/`-n`, `--bare`,
286or `--mirror` is given)
Junio C Hamano0e066b92009-08-28 01:08:41287
Junio C Hamanoccdabca2016-05-06 22:27:09288--[no-]shallow-submodules::
289All submodules which are cloned will be shallow with a depth of 1.
290
Junio C Hamano73c64862019-06-18 03:24:20291--[no-]remote-submodules::
Junio C Hamano2f5a9892019-12-25 21:12:55292All submodules which are cloned will use the status of the submodule's
Junio C Hamano73c64862019-06-18 03:24:20293remote-tracking branch to update the submodule, rather than the
Junio C Hamano2f5a9892019-12-25 21:12:55294superproject's recorded SHA-1. Equivalent to passing `--remote` to
Junio C Hamano73c64862019-06-18 03:24:20295`git submodule update`.
296
Junio C Hamano59a32b02021-12-10 22:53:38297--separate-git-dir=<git-dir>::
Junio C Hamanoa03ac862011-04-02 04:32:29298Instead of placing the cloned repository where it is supposed
299to be, place the cloned repository at the specified directory,
Junio C Hamano826f5c42014-02-07 20:33:30300then make a filesystem-agnostic Git symbolic link to there.
Junio C Hamano076ffcc2013-02-06 05:13:21301The result is Git repository can be separated from working
Junio C Hamanoa03ac862011-04-02 04:32:29302tree.
303
Junio C Hamanobec5da42016-04-06 22:58:21304-j <n>::
305--jobs <n>::
306The number of submodules fetched at the same time.
307Defaults to the `submodule.fetchJobs` option.
Junio C Hamanoa03ac862011-04-02 04:32:29308
Junio C Hamano1a4e8412005-12-27 08:17:23309<repository>::
Junio C Hamano330aae62007-07-06 17:01:58310The (possibly remote) repository to clone from. See the
Junio C Hamanoccb82522018-05-08 07:52:09311<<URLS,GIT URLS>> section below for more information on specifying
Junio C Hamano330aae62007-07-06 17:01:58312repositories.
Junio C Hamano1a4e8412005-12-27 08:17:23313
314<directory>::
Junio C Hamano8db10ef2006-06-09 04:31:57315The name of a new directory to clone into. The "humanish"
Junio C Hamano1a4e8412005-12-27 08:17:23316part of the source repository is used if no directory is
Junio C Hamano621e1232009-10-26 05:16:47317explicitly given (`repo` for `/path/to/repo.git` and `foo`
318for `host.xz:foo/.git`). Cloning into an existing directory
Junio C Hamano89bdb3b2009-05-10 06:48:14319is only allowed if the directory is empty.
Junio C Hamano1a4e8412005-12-27 08:17:23320
Junio C Hamano63777e22007-11-17 20:52:16321:git-clone: 1
Junio C Hamano330aae62007-07-06 17:01:58322include::urls.txt[]
323
Junio C Hamanob9d9d902018-05-23 07:07:42324EXAMPLES
Junio C Hamano1bb569e2006-05-05 23:14:25325--------
Junio C Hamano1a4e8412005-12-27 08:17:23326
Junio C Hamano9ccf6642010-03-22 01:47:35327* Clone from upstream:
Junio C Hamano1a4e8412005-12-27 08:17:23328+
329------------
Junio C Hamanoa1952302013-07-01 21:31:18330$ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux
331$ cd my-linux
Junio C Hamano1a4e8412005-12-27 08:17:23332$ make
333------------
334
335
Junio C Hamano9ccf6642010-03-22 01:47:35336* Make a local clone that borrows from the current directory, without checking things out:
Junio C Hamano1a4e8412005-12-27 08:17:23337+
338------------
339$ git clone -l -s -n . ../copy
Junio C Hamano8638c922007-05-12 20:50:08340$ cd ../copy
Junio C Hamano1a4e8412005-12-27 08:17:23341$ git show-branch
342------------
343
Junio C Hamano38064d52006-01-15 10:13:49344
Junio C Hamano9ccf6642010-03-22 01:47:35345* Clone from upstream while borrowing from an existing local directory:
Junio C Hamanof50bfec2006-04-19 09:44:12346+
347------------
Junio C Hamanoa1952302013-07-01 21:31:18348$ git clone --reference /git/linux.git \
349git://git.kernel.org/pub/scm/.../linux.git \
350my-linux
351$ cd my-linux
Junio C Hamanof50bfec2006-04-19 09:44:12352------------
353
354
Junio C Hamano9ccf6642010-03-22 01:47:35355* Create a bare repository to publish your changes to the public:
Junio C Hamano38064d52006-01-15 10:13:49356+
357------------
Junio C Hamanoe663a7a2006-01-25 12:37:28358$ git clone --bare -l /home/proj/.git /pub/scm/proj.git
Junio C Hamano38064d52006-01-15 10:13:49359------------
360
361
Junio C Hamano1a4e8412005-12-27 08:17:23362GIT
363---
Junio C Hamanof7c042d2008-06-06 22:50:53364Part of the linkgit:git[1] suite