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                 [--jobs <n>] [--] <repository> [<directory>]
16
17

DESCRIPTION

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

OPTIONS

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

GIT URLS

249       In general, URLs contain information about the transport protocol, the
250       address of the remote server, and the path to the repository. Depending
251       on the transport protocol, some of this information may be absent.
252
253       Git supports ssh, git, http, and https protocols (in addition, ftp, and
254       ftps can be used for fetching, but this is inefficient and deprecated;
255       do not use it).
256
257       The native transport (i.e. git:// URL) does no authentication and
258       should be used with caution on unsecured networks.
259
260       The following syntaxes may be used with them:
261
262       ·   ssh://[user@]host.xz[:port]/path/to/repo.git/
263
264       ·   git://host.xz[:port]/path/to/repo.git/
265
266       ·   http[s]://host.xz[:port]/path/to/repo.git/
267
268       ·   ftp[s]://host.xz[:port]/path/to/repo.git/
269
270       An alternative scp-like syntax may also be used with the ssh protocol:
271
272       ·   [user@]host.xz:path/to/repo.git/
273
274       This syntax is only recognized if there are no slashes before the first
275       colon. This helps differentiate a local path that contains a colon. For
276       example the local path foo:bar could be specified as an absolute path
277       or ./foo:bar to avoid being misinterpreted as an ssh url.
278
279       The ssh and git protocols additionally support ~username expansion:
280
281       ·   ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
282
283       ·   git://host.xz[:port]/~[user]/path/to/repo.git/
284
285       ·   [user@]host.xz:/~[user]/path/to/repo.git/
286
287       For local repositories, also supported by Git natively, the following
288       syntaxes may be used:
289
290       ·   /path/to/repo.git/
291
292       ·   file:///path/to/repo.git/
293
294       These two syntaxes are mostly equivalent, except the former implies
295       --local option.
296
297       When Git doesn’t know how to handle a certain transport protocol, it
298       attempts to use the remote-<transport> remote helper, if one exists. To
299       explicitly request a remote helper, the following syntax may be used:
300
301       ·   <transport>::<address>
302
303       where <address> may be a path, a server and path, or an arbitrary
304       URL-like string recognized by the specific remote helper being invoked.
305       See gitremote-helpers(1) for details.
306
307       If there are a large number of similarly-named remote repositories and
308       you want to use a different format for them (such that the URLs you use
309       will be rewritten into URLs that work), you can create a configuration
310       section of the form:
311
312                   [url "<actual url base>"]
313                           insteadOf = <other url base>
314
315
316       For example, with this:
317
318                   [url "git://git.host.xz/"]
319                           insteadOf = host.xz:/path/to/
320                           insteadOf = work:
321
322
323       a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
324       rewritten in any context that takes a URL to be
325       "git://git.host.xz/repo.git".
326
327       If you want to rewrite URLs for push only, you can create a
328       configuration section of the form:
329
330                   [url "<actual url base>"]
331                           pushInsteadOf = <other url base>
332
333
334       For example, with this:
335
336                   [url "ssh://example.org/"]
337                           pushInsteadOf = git://example.org/
338
339
340       a URL like "git://example.org/path/to/repo.git" will be rewritten to
341       "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
342       use the original URL.
343

EXAMPLES

345       ·   Clone from upstream:
346
347               $ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux
348               $ cd my-linux
349               $ make
350
351
352       ·   Make a local clone that borrows from the current directory, without
353           checking things out:
354
355               $ git clone -l -s -n . ../copy
356               $ cd ../copy
357               $ git show-branch
358
359
360       ·   Clone from upstream while borrowing from an existing local
361           directory:
362
363               $ git clone --reference /git/linux.git \
364                       git://git.kernel.org/pub/scm/.../linux.git \
365                       my-linux
366               $ cd my-linux
367
368
369       ·   Create a bare repository to publish your changes to the public:
370
371               $ git clone --bare -l /home/proj/.git /pub/scm/proj.git
372
373

GIT

375       Part of the git(1) suite
376
377
378
379Git 2.21.0                        02/24/2019                      GIT-CLONE(1)
Impressum