1GIT-CLONE(1)                      Git Manual                      GIT-CLONE(1)
2
3
4

NAME

6       git-clone - Clone a repository into a new directory
7

SYNOPSIS

9       git clone [--template=<template-directory>]
10                 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
11                 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
12                 [--dissociate] [--separate-git-dir <git-dir>]
13                 [--depth <depth>] [--[no-]single-branch] [--no-tags]
14                 [--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
15                 [--[no-]remote-submodules] [--jobs <n>] [--sparse] [--[no-]reject-shallow]
16                 [--filter=<filter> [--also-filter-submodules]] [--] <repository>
17                 [<directory>]
18

DESCRIPTION

20       Clones a repository into a newly created directory, creates
21       remote-tracking branches for each branch in the cloned repository
22       (visible using git branch --remotes), and creates and checks out an
23       initial branch that is forked from the cloned repository’s currently
24       active branch.
25
26       After the clone, a plain git fetch without arguments will update all
27       the remote-tracking branches, and a git pull without arguments will in
28       addition merge the remote master branch into the current master branch,
29       if any (this is untrue when "--single-branch" is given; see below).
30
31       This default configuration is achieved by creating references to the
32       remote branch heads under refs/remotes/origin and by initializing
33       remote.origin.url and remote.origin.fetch configuration variables.
34

OPTIONS

36       -l, --local
37           When the repository to clone from is on a local machine, this flag
38           bypasses the normal "Git aware" transport mechanism and clones the
39           repository by making a copy of HEAD and everything under objects
40           and refs directories. The files under .git/objects/ directory are
41           hardlinked to save space when possible.
42
43           If the repository is specified as a local path (e.g.,
44           /path/to/repo), this is the default, and --local is essentially a
45           no-op. If the repository is specified as a URL, then this flag is
46           ignored (and we never use the local optimizations). Specifying
47           --no-local will override the default when /path/to/repo is given,
48           using the regular Git transport instead.
49
50           If the repository’s $GIT_DIR/objects has symbolic links or is a
51           symbolic link, the clone will fail. This is a security measure to
52           prevent the unintentional copying of files by dereferencing the
53           symbolic links.
54
55           NOTE: this operation can race with concurrent modification to the
56           source repository, similar to running cp -r src dst while modifying
57           src.
58
59       --no-hardlinks
60           Force the cloning process from a repository on a local filesystem
61           to copy the files under the .git/objects directory instead of using
62           hardlinks. This may be desirable if you are trying to make a
63           back-up of your repository.
64
65       -s, --shared
66           When the repository to clone is on the local machine, instead of
67           using hard links, automatically setup .git/objects/info/alternates
68           to share the objects with the source repository. The resulting
69           repository starts out without any object of its own.
70
71           NOTE: this is a possibly dangerous operation; do not use it unless
72           you understand what it does. If you clone your repository using
73           this option and then delete branches (or use any other Git command
74           that makes any existing commit unreferenced) in the source
75           repository, some objects may become unreferenced (or dangling).
76           These objects may be removed by normal Git operations (such as git
77           commit) which automatically call git maintenance run --auto. (See
78           git-maintenance(1).) If these objects are removed and were
79           referenced by the cloned repository, then the cloned repository
80           will become corrupt.
81
82           Note that running git repack without the --local option in a
83           repository cloned with --shared will copy objects from the source
84           repository into a pack in the cloned repository, removing the disk
85           space savings of clone --shared. It is safe, however, to run git
86           gc, which uses the --local option by default.
87
88           If you want to break the dependency of a repository cloned with
89           --shared on its source repository, you can simply run git repack -a
90           to copy all objects from the source repository into a pack in the
91           cloned repository.
92
93       --reference[-if-able] <repository>
94           If the reference repository is on the local machine, automatically
95           setup .git/objects/info/alternates to obtain objects from the
96           reference repository. Using an already existing repository as an
97           alternate will require fewer objects to be copied from the
98           repository being cloned, reducing network and local storage costs.
99           When using the --reference-if-able, a non existing directory is
100           skipped with a warning instead of aborting the clone.
101
102           NOTE: see the NOTE for the --shared option, and also the
103           --dissociate option.
104
105       --dissociate
106           Borrow the objects from reference repositories specified with the
107           --reference options only to reduce network transfer, and stop
108           borrowing from them after a clone is made by making necessary local
109           copies of borrowed objects. This option can also be used when
110           cloning locally from a repository that already borrows objects from
111           another repository—the new repository will borrow objects from the
112           same repository, and this option can be used to stop the borrowing.
113
114       -q, --quiet
115           Operate quietly. Progress is not reported to the standard error
116           stream.
117
118       -v, --verbose
119           Run verbosely. Does not affect the reporting of progress status to
120           the standard error stream.
121
122       --progress
123           Progress status is reported on the standard error stream by default
124           when it is attached to a terminal, unless --quiet is specified.
125           This flag forces progress status even if the standard error stream
126           is not directed to a terminal.
127
128       --server-option=<option>
129           Transmit the given string to the server when communicating using
130           protocol version 2. The given string must not contain a NUL or LF
131           character. The server’s handling of server options, including
132           unknown ones, is server-specific. When multiple
133           --server-option=<option> are given, they are all sent to the other
134           side in the order listed on the command line.
135
136       -n, --no-checkout
137           No checkout of HEAD is performed after the clone is complete.
138
139       --[no-]reject-shallow
140           Fail if the source repository is a shallow repository. The
141           clone.rejectShallow configuration variable can be used to specify
142           the default.
143
144       --bare
145           Make a bare Git repository. That is, instead of creating
146           <directory> and placing the administrative files in
147           <directory>/.git, make the <directory> itself the $GIT_DIR. This
148           obviously implies the --no-checkout because there is nowhere to
149           check out the working tree. Also the branch heads at the remote are
150           copied directly to corresponding local branch heads, without
151           mapping them to refs/remotes/origin/. When this option is used,
152           neither remote-tracking branches nor the related configuration
153           variables are created.
154
155       --sparse
156           Employ a sparse-checkout, with only files in the toplevel directory
157           initially being present. The git-sparse-checkout(1) command can be
158           used to grow the working directory as needed.
159
160       --filter=<filter-spec>
161           Use the partial clone feature and request that the server sends a
162           subset of reachable objects according to a given object filter.
163           When using --filter, the supplied <filter-spec> is used for the
164           partial clone filter. For example, --filter=blob:none will filter
165           out all blobs (file contents) until needed by Git. Also,
166           --filter=blob:limit=<size> will filter out all blobs of size at
167           least <size>. For more details on filter specifications, see the
168           --filter option in git-rev-list(1).
169
170       --also-filter-submodules
171           Also apply the partial clone filter to any submodules in the
172           repository. Requires --filter and --recurse-submodules. This can be
173           turned on by default by setting the clone.filterSubmodules config
174           option.
175
176       --mirror
177           Set up a mirror of the source repository. This implies --bare.
178           Compared to --bare, --mirror not only maps local branches of the
179           source to local branches of the target, it maps all refs (including
180           remote-tracking branches, notes etc.) and sets up a refspec
181           configuration such that all these refs are overwritten by a git
182           remote update in the target repository.
183
184       -o <name>, --origin <name>
185           Instead of using the remote name origin to keep track of the
186           upstream repository, use <name>. Overrides clone.defaultRemoteName
187           from the config.
188
189       -b <name>, --branch <name>
190           Instead of pointing the newly created HEAD to the branch pointed to
191           by the cloned repository’s HEAD, point to <name> branch instead. In
192           a non-bare repository, this is the branch that will be checked out.
193           --branch can also take tags and detaches the HEAD at that commit in
194           the resulting repository.
195
196       -u <upload-pack>, --upload-pack <upload-pack>
197           When given, and the repository to clone from is accessed via ssh,
198           this specifies a non-default path for the command run on the other
199           end.
200
201       --template=<template-directory>
202           Specify the directory from which templates will be used; (See the
203           "TEMPLATE DIRECTORY" section of git-init(1).)
204
205       -c <key>=<value>, --config <key>=<value>
206           Set a configuration variable in the newly-created repository; this
207           takes effect immediately after the repository is initialized, but
208           before the remote history is fetched or any files checked out. The
209           key is in the same format as expected by git-config(1) (e.g.,
210           core.eol=true). If multiple values are given for the same key, each
211           value will be written to the config file. This makes it safe, for
212           example, to add additional fetch refspecs to the origin remote.
213
214           Due to limitations of the current implementation, some
215           configuration variables do not take effect until after the initial
216           fetch and checkout. Configuration variables known to not take
217           effect are: remote.<name>.mirror and remote.<name>.tagOpt. Use the
218           corresponding --mirror and --no-tags options instead.
219
220       --depth <depth>
221           Create a shallow clone with a history truncated to the specified
222           number of commits. Implies --single-branch unless
223           --no-single-branch is given to fetch the histories near the tips of
224           all branches. If you want to clone submodules shallowly, also pass
225           --shallow-submodules.
226
227       --shallow-since=<date>
228           Create a shallow clone with a history after the specified time.
229
230       --shallow-exclude=<revision>
231           Create a shallow clone with a history, excluding commits reachable
232           from a specified remote branch or tag. This option can be specified
233           multiple times.
234
235       --[no-]single-branch
236           Clone only the history leading to the tip of a single branch,
237           either specified by the --branch option or the primary branch
238           remote’s HEAD points at. Further fetches into the resulting
239           repository will only update the remote-tracking branch for the
240           branch this option was used for the initial cloning. If the HEAD at
241           the remote did not point at any branch when --single-branch clone
242           was made, no remote-tracking branch is created.
243
244       --no-tags
245           Don’t clone any tags, and set remote.<remote>.tagOpt=--no-tags in
246           the config, ensuring that future git pull and git fetch operations
247           won’t follow any tags. Subsequent explicit tag fetches will still
248           work, (see git-fetch(1)).
249
250           Can be used in conjunction with --single-branch to clone and
251           maintain a branch with no references other than a single cloned
252           branch. This is useful e.g. to maintain minimal clones of the
253           default branch of some repository for search indexing.
254
255       --recurse-submodules[=<pathspec>]
256           After the clone is created, initialize and clone submodules within
257           based on the provided pathspec. If no pathspec is provided, all
258           submodules are initialized and cloned. This option can be given
259           multiple times for pathspecs consisting of multiple entries. The
260           resulting clone has submodule.active set to the provided pathspec,
261           or "." (meaning all submodules) if no pathspec is provided.
262
263           Submodules are initialized and cloned using their default settings.
264           This is equivalent to running git submodule update --init
265           --recursive <pathspec> immediately after the clone is finished.
266           This option is ignored if the cloned repository does not have a
267           worktree/checkout (i.e. if any of --no-checkout/-n, --bare, or
268           --mirror is given)
269
270       --[no-]shallow-submodules
271           All submodules which are cloned will be shallow with a depth of 1.
272
273       --[no-]remote-submodules
274           All submodules which are cloned will use the status of the
275           submodule’s remote-tracking branch to update the submodule, rather
276           than the superproject’s recorded SHA-1. Equivalent to passing
277           --remote to git submodule update.
278
279       --separate-git-dir=<git-dir>
280           Instead of placing the cloned repository where it is supposed to
281           be, place the cloned repository at the specified directory, then
282           make a filesystem-agnostic Git symbolic link to there. The result
283           is Git repository can be separated from working tree.
284
285       -j <n>, --jobs <n>
286           The number of submodules fetched at the same time. Defaults to the
287           submodule.fetchJobs option.
288
289       <repository>
290           The (possibly remote) repository to clone from. See the GIT URLS
291           section below for more information on specifying repositories.
292
293       <directory>
294           The name of a new directory to clone into. The "humanish" part of
295           the source repository is used if no directory is explicitly given
296           (repo for /path/to/repo.git and foo for host.xz:foo/.git). Cloning
297           into an existing directory is only allowed if the directory is
298           empty.
299
300       --bundle-uri=<uri>
301           Before fetching from the remote, fetch a bundle from the given
302           <uri> and unbundle the data into the local repository. The refs in
303           the bundle will be stored under the hidden refs/bundle/* namespace.
304           This option is incompatible with --depth, --shallow-since, and
305           --shallow-exclude.
306

GIT URLS

308       In general, URLs contain information about the transport protocol, the
309       address of the remote server, and the path to the repository. Depending
310       on the transport protocol, some of this information may be absent.
311
312       Git supports ssh, git, http, and https protocols (in addition, ftp and
313       ftps can be used for fetching, but this is inefficient and deprecated;
314       do not use them).
315
316       The native transport (i.e. git:// URL) does no authentication and
317       should be used with caution on unsecured networks.
318
319       The following syntaxes may be used with them:
320
321       •   ssh://[user@]host.xz[:port]/path/to/repo.git/
322
323       •   git://host.xz[:port]/path/to/repo.git/
324
325       •   http[s]://host.xz[:port]/path/to/repo.git/
326
327       •   ftp[s]://host.xz[:port]/path/to/repo.git/
328
329       An alternative scp-like syntax may also be used with the ssh protocol:
330
331       •   [user@]host.xz:path/to/repo.git/
332
333       This syntax is only recognized if there are no slashes before the first
334       colon. This helps differentiate a local path that contains a colon. For
335       example the local path foo:bar could be specified as an absolute path
336       or ./foo:bar to avoid being misinterpreted as an ssh url.
337
338       The ssh and git protocols additionally support ~username expansion:
339
340       •   ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
341
342       •   git://host.xz[:port]/~[user]/path/to/repo.git/
343
344       •   [user@]host.xz:/~[user]/path/to/repo.git/
345
346       For local repositories, also supported by Git natively, the following
347       syntaxes may be used:
348
349       •   /path/to/repo.git/
350
351       •   file:///path/to/repo.git/
352
353       These two syntaxes are mostly equivalent, except the former implies
354       --local option.
355
356       git clone, git fetch and git pull, but not git push, will also accept a
357       suitable bundle file. See git-bundle(1).
358
359       When Git doesn’t know how to handle a certain transport protocol, it
360       attempts to use the remote-<transport> remote helper, if one exists. To
361       explicitly request a remote helper, the following syntax may be used:
362
363       •   <transport>::<address>
364
365       where <address> may be a path, a server and path, or an arbitrary
366       URL-like string recognized by the specific remote helper being invoked.
367       See gitremote-helpers(7) for details.
368
369       If there are a large number of similarly-named remote repositories and
370       you want to use a different format for them (such that the URLs you use
371       will be rewritten into URLs that work), you can create a configuration
372       section of the form:
373
374                   [url "<actual url base>"]
375                           insteadOf = <other url base>
376
377       For example, with this:
378
379                   [url "git://git.host.xz/"]
380                           insteadOf = host.xz:/path/to/
381                           insteadOf = work:
382
383       a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
384       rewritten in any context that takes a URL to be
385       "git://git.host.xz/repo.git".
386
387       If you want to rewrite URLs for push only, you can create a
388       configuration section of the form:
389
390                   [url "<actual url base>"]
391                           pushInsteadOf = <other url base>
392
393       For example, with this:
394
395                   [url "ssh://example.org/"]
396                           pushInsteadOf = git://example.org/
397
398       a URL like "git://example.org/path/to/repo.git" will be rewritten to
399       "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
400       use the original URL.
401

EXAMPLES

403       •   Clone from upstream:
404
405               $ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux
406               $ cd my-linux
407               $ make
408
409       •   Make a local clone that borrows from the current directory, without
410           checking things out:
411
412               $ git clone -l -s -n . ../copy
413               $ cd ../copy
414               $ git show-branch
415
416       •   Clone from upstream while borrowing from an existing local
417           directory:
418
419               $ git clone --reference /git/linux.git \
420                       git://git.kernel.org/pub/scm/.../linux.git \
421                       my-linux
422               $ cd my-linux
423
424       •   Create a bare repository to publish your changes to the public:
425
426               $ git clone --bare -l /home/proj/.git /pub/scm/proj.git
427

CONFIGURATION

429       Everything below this line in this section is selectively included from
430       the git-config(1) documentation. The content is the same as what’s
431       found there:
432
433       init.templateDir
434           Specify the directory from which templates will be copied. (See the
435           "TEMPLATE DIRECTORY" section of git-init(1).)
436
437       init.defaultBranch
438           Allows overriding the default branch name e.g. when initializing a
439           new repository.
440
441       clone.defaultRemoteName
442           The name of the remote to create when cloning a repository.
443           Defaults to origin, and can be overridden by passing the --origin
444           command-line option to git-clone(1).
445
446       clone.rejectShallow
447           Reject cloning a repository if it is a shallow one; this can be
448           overridden by passing the --reject-shallow option on the command
449           line. See git-clone(1)
450
451       clone.filterSubmodules
452           If a partial clone filter is provided (see --filter in git-rev-
453           list(1)) and --recurse-submodules is used, also apply the filter to
454           submodules.
455

GIT

457       Part of the git(1) suite
458
459
460
461Git 2.43.0                        11/20/2023                      GIT-CLONE(1)
Impressum