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

GIT URLS

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

EXAMPLES

360       ·   Clone from upstream:
361
362               $ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux
363               $ cd my-linux
364               $ make
365
366
367       ·   Make a local clone that borrows from the current directory, without
368           checking things out:
369
370               $ git clone -l -s -n . ../copy
371               $ cd ../copy
372               $ git show-branch
373
374
375       ·   Clone from upstream while borrowing from an existing local
376           directory:
377
378               $ git clone --reference /git/linux.git \
379                       git://git.kernel.org/pub/scm/.../linux.git \
380                       my-linux
381               $ cd my-linux
382
383
384       ·   Create a bare repository to publish your changes to the public:
385
386               $ git clone --bare -l /home/proj/.git /pub/scm/proj.git
387
388

GIT

390       Part of the git(1) suite
391
392
393
394Git 2.24.1                        12/10/2019                      GIT-CLONE(1)
Impressum