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

GIT URLS

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

EXAMPLES

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

CONFIGURATION

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

GIT

452       Part of the git(1) suite
453
454
455
456Git 2.39.1                        2023-01-13                      GIT-CLONE(1)
Impressum