Git fork
1git-clone(1)
2============
3
4NAME
5----
6git-clone - Clone a repository into a new directory
7
8
9SYNOPSIS
10--------
11[synopsis]
12git clone [--template=<template-directory>]
13 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
14 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
15 [--dissociate] [--separate-git-dir <git-dir>]
16 [--depth <depth>] [--[no-]single-branch] [--[no-]tags]
17 [--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
18 [--[no-]remote-submodules] [--jobs <n>] [--sparse] [--[no-]reject-shallow]
19 [--filter=<filter-spec> [--also-filter-submodules]] [--] <repository>
20 [<directory>]
21
22DESCRIPTION
23-----------
24
25Clones a repository into a newly created directory, creates
26remote-tracking branches for each branch in the cloned repository
27(visible using `git branch --remotes`), and creates and checks out an
28initial branch that is forked from the cloned repository's
29currently active branch.
30
31After 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
34current master branch, if any (this is untrue when `--single-branch`
35is given; see below).
36
37This default configuration is achieved by creating references to
38the remote branch heads under `refs/remotes/origin` and
39by initializing `remote.origin.url` and `remote.origin.fetch`
40configuration variables.
41
42
43OPTIONS
44-------
45`-l`::
46`--local`::
47 When the repository to clone from is on a local machine,
48 this flag bypasses the normal "Git aware" transport
49 mechanism and clones the repository by making a copy of
50 `HEAD` and everything under objects and refs directories.
51 The files under `.git/objects/` directory are hardlinked
52 to 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
59Git transport instead.
60+
61If the repository's `$GIT_DIR/objects` has symbolic links or is a
62symbolic link, the clone will fail. This is a security measure to
63prevent the unintentional copying of files by dereferencing the symbolic
64links.
65+
66This option does not work with repositories owned by other users for security
67reasons, and `--no-local` must be specified for the clone to succeed.
68+
69*NOTE*: this operation can race with concurrent modification to the
70source repository, similar to running `cp -r <src> <dst>` while modifying
71_<src>_.
72
73`--no-hardlinks`::
74 Force the cloning process from a repository on a local
75 filesystem to copy the files under the `.git/objects`
76 directory instead of using hardlinks. This may be desirable
77 if you are trying to make a back-up of your repository.
78
79`-s`::
80`--shared`::
81 When the repository to clone is on the local machine,
82 instead of using hard links, automatically setup
83 `.git/objects/info/alternates` to share the objects
84 with the source repository. The resulting repository
85 starts out without any object of its own.
86+
87*NOTE*: this is a possibly dangerous operation; do *not* use
88it unless you understand what it does. If you clone your
89repository using this option and then delete branches (or use any
90other Git command that makes any existing commit unreferenced) in the
91source repository, some objects may become unreferenced (or dangling).
92These objects may be removed by normal Git operations (such as `git commit`)
93which automatically call `git maintenance run --auto`. (See
94linkgit:git-maintenance[1].) If these objects are removed and were referenced
95by the cloned repository, then the cloned repository will become corrupt.
96+
97Note that running `git repack` without the `--local` option in a repository
98cloned with `--shared` will copy objects from the source repository into a pack
99in the cloned repository, removing the disk space savings of `clone --shared`.
100It is safe, however, to run `git gc`, which uses the `--local` option by
101default.
102+
103If you want to break the dependency of a repository cloned with `--shared` on
104its source repository, you can simply run `git repack -a` to copy all
105objects from the source repository into a pack in the cloned repository.
106
107`--reference[-if-able] <repository>`::
108 If the reference _<repository>_ is on the local machine,
109 automatically setup `.git/objects/info/alternates` to
110 obtain objects from the reference _<repository>_. Using
111 an already existing repository as an alternate will
112 require fewer objects to be copied from the repository
113 being cloned, reducing network and local storage costs.
114 When using the `--reference-if-able`, a non existing
115 directory is skipped with a warning instead of aborting
116 the clone.
117+
118*NOTE*: see the NOTE for the `--shared` option, and also the
119`--dissociate` option.
120
121`--dissociate`::
122 Borrow the objects from reference repositories specified
123 with the `--reference` options only to reduce network
124 transfer, and stop borrowing from them after a clone is made
125 by making necessary local copies of borrowed objects. This
126 option can also be used when cloning locally from a
127 repository that already borrows objects from another
128 repository--the new repository will borrow objects from the
129 same repository, and this option can be used to stop the
130 borrowing.
131
132`-q`::
133`--quiet`::
134 Operate quietly. Progress is not reported to the standard
135 error stream.
136
137`-v`::
138`--verbose`::
139 Run verbosely. Does not affect the reporting of progress status
140 to the standard error stream.
141
142`--progress`::
143 Progress status is reported on the standard error stream
144 by default when it is attached to a terminal, unless `--quiet`
145 is specified. This flag forces progress status even if the
146 standard error stream is not directed to a terminal.
147
148`--server-option=<option>`::
149 Transmit the given string to the server when communicating using
150 protocol version 2. The given string must not contain a NUL or LF
151 character. The server's handling of server options, including
152 unknown ones, is server-specific.
153 When multiple `--server-option=<option>` are given, they are all
154 sent to the other side in the order listed on the command line.
155 When no ++--server-option=++__<option>__ is given from the command
156 line, the values of configuration variable `remote.<name>.serverOption`
157 are used instead.
158
159`-n`::
160`--no-checkout`::
161 No checkout of `HEAD` is performed after the clone is complete.
162
163`--`[`no-`]`reject-shallow`::
164 Fail if the source repository is a shallow repository.
165 The `clone.rejectShallow` configuration variable can be used to
166 specify the default.
167
168`--bare`::
169 Make a 'bare' Git repository. That is, instead of
170 creating _<directory>_ and placing the administrative
171 files in `<directory>/.git`, make the _<directory>_
172 itself the `$GIT_DIR`. This obviously implies the `--no-checkout`
173 because there is nowhere to check out the working tree.
174 Also the branch heads at the remote are copied directly
175 to corresponding local branch heads, without mapping
176 them to `refs/remotes/origin/`. When this option is
177 used, neither remote-tracking branches nor the related
178 configuration variables are created.
179
180`--sparse`::
181 Employ a sparse-checkout, with only files in the toplevel
182 directory initially being present. The
183 linkgit:git-sparse-checkout[1] command can be used to grow the
184 working directory as needed.
185
186`--filter=<filter-spec>`::
187 Use the partial clone feature and request that the server sends
188 a subset of reachable objects according to a given object filter.
189 When using `--filter`, the supplied _<filter-spec>_ is used for
190 the partial clone filter. For example, `--filter=blob:none` will
191 filter out all blobs (file contents) until needed by Git. Also,
192 `--filter=blob:limit=<size>` will filter out all blobs of size
193 at least _<size>_. For more details on filter specifications, see
194 the `--filter` option in linkgit:git-rev-list[1].
195
196`--also-filter-submodules`::
197 Also apply the partial clone filter to any submodules in the repository.
198 Requires `--filter` and `--recurse-submodules`. This can be turned on by
199 default by setting the `clone.filterSubmodules` config option.
200
201`--mirror`::
202 Set up a mirror of the source repository. This implies `--bare`.
203 Compared to `--bare`, `--mirror` not only maps local branches of the
204 source to local branches of the target, it maps all refs (including
205 remote-tracking branches, notes etc.) and sets up a refspec configuration such
206 that all these refs are overwritten by a `git remote update` in the
207 target repository.
208
209`-o` _<name>_::
210`--origin` _<name>_::
211 Instead of using the remote name `origin` to keep track of the upstream
212 repository, use _<name>_. Overrides `clone.defaultRemoteName` from the
213 config.
214
215`-b` _<name>_::
216`--branch` _<name>_::
217 Instead of pointing the newly created `HEAD` to the branch pointed
218 to by the cloned repository's `HEAD`, point to _<name>_ branch
219 instead. In a non-bare repository, this is the branch that will
220 be checked out.
221 `--branch` can also take tags and detaches the `HEAD` at that commit
222 in the resulting repository.
223
224`--revision=<rev>`::
225 Create a new repository, and fetch the history leading to the given
226 revision _<rev>_ (and nothing else), without making any remote-tracking
227 branch, and without making any local branch, and detach `HEAD` to
228 _<rev>_. The argument can be a ref name (e.g. `refs/heads/main` or
229 `refs/tags/v1.0`) that peels down to a commit, or a hexadecimal object
230 name.
231 This option is incompatible with `--branch` and `--mirror`.
232
233`-u` _<upload-pack>_::
234`--upload-pack` _<upload-pack>_::
235 When given, and the repository to clone from is accessed
236 via ssh, this specifies a non-default path for the command
237 run on the other end.
238
239`--template=<template-directory>`::
240 Specify the directory from which templates will be used;
241 (See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
242
243`-c` `<key>=<value>`::
244`--config` `<key>=<value>`::
245 Set a configuration variable in the newly-created repository;
246 this takes effect immediately after the repository is
247 initialized, but before the remote history is fetched or any
248 files checked out. The _<key>_ is in the same format as expected by
249 linkgit:git-config[1] (e.g., `core.eol=true`). If multiple
250 values are given for the same key, each value will be written to
251 the config file. This makes it safe, for example, to add
252 additional fetch refspecs to the origin remote.
253+
254Due to limitations of the current implementation, some configuration
255variables do not take effect until after the initial fetch and checkout.
256Configuration variables known to not take effect are:
257`remote.<name>.mirror` and `remote.<name>.tagOpt`. Use the
258corresponding `--mirror` and `--no-tags` options instead.
259
260`--depth <depth>`::
261 Create a 'shallow' clone with a history truncated to the
262 specified number of commits. Implies `--single-branch` unless
263 `--no-single-branch` is given to fetch the histories near the
264 tips of all branches. If you want to clone submodules shallowly,
265 also pass `--shallow-submodules`.
266
267`--shallow-since=<date>`::
268 Create a shallow clone with a history after the specified time.
269
270`--shallow-exclude=<ref>`::
271 Create a shallow clone with a history, excluding commits
272 reachable from a specified remote branch or tag. This option
273 can be specified multiple times.
274
275`--single-branch`::
276`--no-single-branch`::
277 Clone only the history leading to the tip of a single branch,
278 either specified by the `--branch` option or the primary
279 branch remote's `HEAD` points at.
280 Further fetches into the resulting repository will only update the
281 remote-tracking branch for the branch this option was used for the
282 initial cloning. If the `HEAD` at the remote did not point at any
283 branch when `--single-branch` clone was made, no remote-tracking
284 branch is created.
285
286`--tags`::
287`--no-tags`::
288 Control whether or not tags will be cloned. When `--no-tags` is
289 given, the option will be become permanent by setting the
290 `remote.<remote>.tagOpt=--no-tags` configuration. This ensures that
291 future `git pull` and `git fetch` won't follow any tags. Subsequent
292 explicit tag fetches will still work (see linkgit:git-fetch[1]).
293+
294By default, tags are cloned and passing `--tags` is thus typically a
295no-op, unless it cancels out a previous `--no-tags`.
296+
297Can be used in conjunction with `--single-branch` to clone and
298maintain a branch with no references other than a single cloned
299branch. This is useful e.g. to maintain minimal clones of the default
300branch of some repository for search indexing.
301
302`--recurse-submodules[=<pathspec>]`::
303 After the clone is created, initialize and clone submodules
304 within based on the provided _<pathspec>_. If no `=<pathspec>` is
305 provided, all submodules are initialized and cloned.
306 This option can be given multiple times for pathspecs consisting
307 of multiple entries. The resulting clone has `submodule.active` set to
308 the provided pathspec, or "`.`" (meaning all submodules) if no
309 pathspec is provided.
310+
311Submodules are initialized and cloned using their default settings. This is
312equivalent to running
313`git submodule update --init --recursive <pathspec>` immediately after
314the clone is finished. This option is ignored if the cloned repository does
315not have a worktree/checkout (i.e. if any of `--no-checkout`/`-n`, `--bare`,
316or `--mirror` is given)
317
318`--shallow-submodules`::
319`--no-shallow-submodules`::
320 All submodules which are cloned will be shallow with a depth of 1.
321
322`--remote-submodules`::
323`--no-remote-submodules`::
324 All submodules which are cloned will use the status of the submodule's
325 remote-tracking branch to update the submodule, rather than the
326 superproject's recorded SHA-1. Equivalent to passing `--remote` to
327 `git submodule update`.
328
329`--separate-git-dir=<git-dir>`::
330 Instead of placing the cloned repository where it is supposed
331 to be, place the cloned repository at the specified directory,
332 then make a filesystem-agnostic Git symbolic link to there.
333 The result is Git repository can be separated from working
334 tree.
335
336`--ref-format=<ref-format>`::
337
338Specify the given ref storage format for the repository. The valid values are:
339+
340include::ref-storage-format.adoc[]
341
342`-j` _<n>_::
343`--jobs` _<n>_::
344 The number of submodules fetched at the same time.
345 Defaults to the `submodule.fetchJobs` option.
346
347_<repository>_::
348 The (possibly remote) _<repository>_ to clone from. See the
349 <<URLS,GIT URLS>> section below for more information on specifying
350 repositories.
351
352_<directory>_::
353 The name of a new directory to clone into. The "humanish"
354 part of the source repository is used if no _<directory>_ is
355 explicitly given (`repo` for `/path/to/repo.git` and `foo`
356 for `host.xz:foo/.git`). Cloning into an existing directory
357 is only allowed if the directory is empty.
358
359`--bundle-uri=<uri>`::
360 Before fetching from the remote, fetch a bundle from the given
361 _<uri>_ and unbundle the data into the local repository. The refs
362 in the bundle will be stored under the hidden `refs/bundle/*`
363 namespace. This option is incompatible with `--depth`,
364 `--shallow-since`, and `--shallow-exclude`.
365
366:git-clone: 1
367include::urls.adoc[]
368
369EXAMPLES
370--------
371
372* Clone from upstream:
373+
374------------
375$ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux
376$ cd my-linux
377$ make
378------------
379
380
381* Make a local clone that borrows from the current directory, without checking things out:
382+
383------------
384$ git clone -l -s -n . ../copy
385$ cd ../copy
386$ git show-branch
387------------
388
389
390* Clone from upstream while borrowing from an existing local directory:
391+
392------------
393$ git clone --reference /git/linux.git \
394 git://git.kernel.org/pub/scm/.../linux.git \
395 my-linux
396$ cd my-linux
397------------
398
399
400* Create a bare repository to publish your changes to the public:
401+
402------------
403$ git clone --bare -l /home/proj/.git /pub/scm/proj.git
404------------
405
406* Clone a local repository from a different user:
407+
408------------
409$ git clone --no-local /home/otheruser/proj.git /pub/scm/proj.git
410------------
411
412CONFIGURATION
413-------------
414
415include::includes/cmd-config-section-all.adoc[]
416
417include::config/init.adoc[]
418
419include::config/clone.adoc[]
420
421
422GIT
423---
424Part of the linkgit:git[1] suite