6 git-clone - Clone a repository into a new directory
12 git 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>
25 Clones a repository into a newly created directory, creates
26 remote-tracking branches for each branch in the cloned repository
27 (visible using `git branch --remotes`), and creates and checks out an
28 initial branch that is forked from the cloned repository's
29 currently active branch.
31 After the clone, a plain `git fetch` without arguments will update
32 all the remote-tracking branches, and a `git pull` without
33 arguments will in addition merge the remote master branch into the
34 current master branch, if any (this is untrue when `--single-branch`
37 This default configuration is achieved by creating references to
38 the remote branch heads under `refs/remotes/origin` and
39 by initializing `remote.origin.url` and `remote.origin.fetch`
40 configuration variables.
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.
54 If the repository is specified as a local path (e.g., `/path/to/repo`),
55 this is the default, and `--local` is essentially a no-op. If the
56 repository is specified as a URL, then this flag is ignored (and we
57 never use the local optimizations). Specifying `--no-local` will
58 override the default when `/path/to/repo` is given, using the regular
59 Git transport instead.
61 If the repository's `$GIT_DIR/objects` has symbolic links or is a
62 symbolic link, the clone will fail. This is a security measure to
63 prevent the unintentional copying of files by dereferencing the symbolic
66 *NOTE*: this operation can race with concurrent modification to the
67 source repository, similar to running `cp -r <src> <dst>` while modifying
71 Force the cloning process from a repository on a local
72 filesystem to copy the files under the `.git/objects`
73 directory instead of using hardlinks. This may be desirable
74 if you are trying to make a back-up of your repository.
78 When the repository to clone is on the local machine,
79 instead of using hard links, automatically setup
80 `.git/objects/info/alternates` to share the objects
81 with the source repository. The resulting repository
82 starts out without any object of its own.
84 *NOTE*: this is a possibly dangerous operation; do *not* use
85 it unless you understand what it does. If you clone your
86 repository using this option and then delete branches (or use any
87 other Git command that makes any existing commit unreferenced) in the
88 source repository, some objects may become unreferenced (or dangling).
89 These objects may be removed by normal Git operations (such as `git commit`)
90 which automatically call `git maintenance run --auto`. (See
91 linkgit:git-maintenance[1].) If these objects are removed and were referenced
92 by the cloned repository, then the cloned repository will become corrupt.
94 Note that running `git repack` without the `--local` option in a repository
95 cloned with `--shared` will copy objects from the source repository into a pack
96 in the cloned repository, removing the disk space savings of `clone --shared`.
97 It is safe, however, to run `git gc`, which uses the `--local` option by
100 If you want to break the dependency of a repository cloned with `--shared` on
101 its source repository, you can simply run `git repack -a` to copy all
102 objects from the source repository into a pack in the cloned repository.
104 `--reference[-if-able] <repository>`::
105 If the reference _<repository>_ is on the local machine,
106 automatically setup `.git/objects/info/alternates` to
107 obtain objects from the reference _<repository>_. Using
108 an already existing repository as an alternate will
109 require fewer objects to be copied from the repository
110 being cloned, reducing network and local storage costs.
111 When using the `--reference-if-able`, a non existing
112 directory is skipped with a warning instead of aborting
115 *NOTE*: see the NOTE for the `--shared` option, and also the
116 `--dissociate` option.
119 Borrow the objects from reference repositories specified
120 with the `--reference` options only to reduce network
121 transfer, and stop borrowing from them after a clone is made
122 by making necessary local copies of borrowed objects. This
123 option can also be used when cloning locally from a
124 repository that already borrows objects from another
125 repository--the new repository will borrow objects from the
126 same repository, and this option can be used to stop the
131 Operate quietly. Progress is not reported to the standard
136 Run verbosely. Does not affect the reporting of progress status
137 to the standard error stream.
140 Progress status is reported on the standard error stream
141 by default when it is attached to a terminal, unless `--quiet`
142 is specified. This flag forces progress status even if the
143 standard error stream is not directed to a terminal.
145 `--server-option=<option>`::
146 Transmit the given string to the server when communicating using
147 protocol version 2. The given string must not contain a NUL or LF
148 character. The server's handling of server options, including
149 unknown ones, is server-specific.
150 When multiple `--server-option=<option>` are given, they are all
151 sent to the other side in the order listed on the command line.
152 When no ++--server-option=++__<option>__ is given from the command
153 line, the values of configuration variable `remote.<name>.serverOption`
158 No checkout of `HEAD` is performed after the clone is complete.
160 `--`[`no-`]`reject-shallow`::
161 Fail if the source repository is a shallow repository.
162 The `clone.rejectShallow` configuration variable can be used to
166 Make a 'bare' Git repository. That is, instead of
167 creating _<directory>_ and placing the administrative
168 files in `<directory>/.git`, make the _<directory>_
169 itself the `$GIT_DIR`. This obviously implies the `--no-checkout`
170 because there is nowhere to check out the working tree.
171 Also the branch heads at the remote are copied directly
172 to corresponding local branch heads, without mapping
173 them to `refs/remotes/origin/`. When this option is
174 used, neither remote-tracking branches nor the related
175 configuration variables are created.
178 Employ a sparse-checkout, with only files in the toplevel
179 directory initially being present. The
180 linkgit:git-sparse-checkout[1] command can be used to grow the
181 working directory as needed.
183 `--filter=<filter-spec>`::
184 Use the partial clone feature and request that the server sends
185 a subset of reachable objects according to a given object filter.
186 When using `--filter`, the supplied _<filter-spec>_ is used for
187 the partial clone filter. For example, `--filter=blob:none` will
188 filter out all blobs (file contents) until needed by Git. Also,
189 `--filter=blob:limit=<size>` will filter out all blobs of size
190 at least _<size>_. For more details on filter specifications, see
191 the `--filter` option in linkgit:git-rev-list[1].
193 `--also-filter-submodules`::
194 Also apply the partial clone filter to any submodules in the repository.
195 Requires `--filter` and `--recurse-submodules`. This can be turned on by
196 default by setting the `clone.filterSubmodules` config option.
199 Set up a mirror of the source repository. This implies `--bare`.
200 Compared to `--bare`, `--mirror` not only maps local branches of the
201 source to local branches of the target, it maps all refs (including
202 remote-tracking branches, notes etc.) and sets up a refspec configuration such
203 that all these refs are overwritten by a `git remote update` in the
207 `--origin` _<name>_::
208 Instead of using the remote name `origin` to keep track of the upstream
209 repository, use _<name>_. Overrides `clone.defaultRemoteName` from the
213 `--branch` _<name>_::
214 Instead of pointing the newly created `HEAD` to the branch pointed
215 to by the cloned repository's `HEAD`, point to _<name>_ branch
216 instead. In a non-bare repository, this is the branch that will
218 `--branch` can also take tags and detaches the `HEAD` at that commit
219 in the resulting repository.
221 `-u` _<upload-pack>_::
222 `--upload-pack` _<upload-pack>_::
223 When given, and the repository to clone from is accessed
224 via ssh, this specifies a non-default path for the command
225 run on the other end.
227 `--template=<template-directory>`::
228 Specify the directory from which templates will be used;
229 (See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
231 `-c` `<key>=<value>`::
232 `--config` `<key>=<value>`::
233 Set a configuration variable in the newly-created repository;
234 this takes effect immediately after the repository is
235 initialized, but before the remote history is fetched or any
236 files checked out. The _<key>_ is in the same format as expected by
237 linkgit:git-config[1] (e.g., `core.eol=true`). If multiple
238 values are given for the same key, each value will be written to
239 the config file. This makes it safe, for example, to add
240 additional fetch refspecs to the origin remote.
242 Due to limitations of the current implementation, some configuration
243 variables do not take effect until after the initial fetch and checkout.
244 Configuration variables known to not take effect are:
245 `remote.<name>.mirror` and `remote.<name>.tagOpt`. Use the
246 corresponding `--mirror` and `--no-tags` options instead.
249 Create a 'shallow' clone with a history truncated to the
250 specified number of commits. Implies `--single-branch` unless
251 `--no-single-branch` is given to fetch the histories near the
252 tips of all branches. If you want to clone submodules shallowly,
253 also pass `--shallow-submodules`.
255 `--shallow-since=<date>`::
256 Create a shallow clone with a history after the specified time.
258 `--shallow-exclude=<ref>`::
259 Create a shallow clone with a history, excluding commits
260 reachable from a specified remote branch or tag. This option
261 can be specified multiple times.
263 `--[no-]single-branch`::
264 Clone only the history leading to the tip of a single branch,
265 either specified by the `--branch` option or the primary
266 branch remote's `HEAD` points at.
267 Further fetches into the resulting repository will only update the
268 remote-tracking branch for the branch this option was used for the
269 initial cloning. If the `HEAD` at the remote did not point at any
270 branch when `--single-branch` clone was made, no remote-tracking
274 Don't clone any tags, and set
275 `remote.<remote>.tagOpt=--no-tags` in the config, ensuring
276 that future `git pull` and `git fetch` operations won't follow
277 any tags. Subsequent explicit tag fetches will still work,
278 (see linkgit:git-fetch[1]).
280 Can be used in conjunction with `--single-branch` to clone and
281 maintain a branch with no references other than a single cloned
282 branch. This is useful e.g. to maintain minimal clones of the default
283 branch of some repository for search indexing.
285 `--recurse-submodules[=<pathspec>]`::
286 After the clone is created, initialize and clone submodules
287 within based on the provided _<pathspec>_. If no `=<pathspec>` is
288 provided, all submodules are initialized and cloned.
289 This option can be given multiple times for pathspecs consisting
290 of multiple entries. The resulting clone has `submodule.active` set to
291 the provided pathspec, or "`.`" (meaning all submodules) if no
292 pathspec is provided.
294 Submodules are initialized and cloned using their default settings. This is
295 equivalent to running
296 `git submodule update --init --recursive <pathspec>` immediately after
297 the clone is finished. This option is ignored if the cloned repository does
298 not have a worktree/checkout (i.e. if any of `--no-checkout`/`-n`, `--bare`,
299 or `--mirror` is given)
301 `--[no-]shallow-submodules`::
302 All submodules which are cloned will be shallow with a depth of 1.
304 `--[no-]remote-submodules`::
305 All submodules which are cloned will use the status of the submodule's
306 remote-tracking branch to update the submodule, rather than the
307 superproject's recorded SHA-1. Equivalent to passing `--remote` to
308 `git submodule update`.
310 `--separate-git-dir=<git-dir>`::
311 Instead of placing the cloned repository where it is supposed
312 to be, place the cloned repository at the specified directory,
313 then make a filesystem-agnostic Git symbolic link to there.
314 The result is Git repository can be separated from working
317 `--ref-format=<ref-format>`::
319 Specify the given ref storage format for the repository. The valid values are:
321 include::ref-storage-format.txt[]
325 The number of submodules fetched at the same time.
326 Defaults to the `submodule.fetchJobs` option.
329 The (possibly remote) _<repository>_ to clone from. See the
330 <<URLS,GIT URLS>> section below for more information on specifying
334 The name of a new directory to clone into. The "humanish"
335 part of the source repository is used if no _<directory>_ is
336 explicitly given (`repo` for `/path/to/repo.git` and `foo`
337 for `host.xz:foo/.git`). Cloning into an existing directory
338 is only allowed if the directory is empty.
340 `--bundle-uri=<uri>`::
341 Before fetching from the remote, fetch a bundle from the given
342 _<uri>_ and unbundle the data into the local repository. The refs
343 in the bundle will be stored under the hidden `refs/bundle/*`
344 namespace. This option is incompatible with `--depth`,
345 `--shallow-since`, and `--shallow-exclude`.
353 * Clone from upstream:
356 $ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux
362 * Make a local clone that borrows from the current directory, without checking things out:
365 $ git clone -l -s -n . ../copy
371 * Clone from upstream while borrowing from an existing local directory:
374 $ git clone --reference /git/linux.git \
375 git://git.kernel.org/pub/scm/.../linux.git \
381 * Create a bare repository to publish your changes to the public:
384 $ git clone --bare -l /home/proj/.git /pub/scm/proj.git
390 include::includes/cmd-config-section-all.txt[]
392 include::config/init.txt[]
394 include::config/clone.txt[]
399 Part of the linkgit:git[1] suite