3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.38.1.220.g9388e93f00
10 .TH "GIT\-CLONE" "1" "10/27/2022" "Git 2\&.38\&.1\&.220\&.g9388e9" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-clone \- Clone a repository into a new directory
35 \fIgit clone\fR [\-\-template=<template\-directory>]
36 [\-l] [\-s] [\-\-no\-hardlinks] [\-q] [\-n] [\-\-bare] [\-\-mirror]
37 [\-o <name>] [\-b <name>] [\-u <upload\-pack>] [\-\-reference <repository>]
38 [\-\-dissociate] [\-\-separate\-git\-dir <git\-dir>]
39 [\-\-depth <depth>] [\-\-[no\-]single\-branch] [\-\-no\-tags]
40 [\-\-recurse\-submodules[=<pathspec>]] [\-\-[no\-]shallow\-submodules]
41 [\-\-[no\-]remote\-submodules] [\-\-jobs <n>] [\-\-sparse] [\-\-[no\-]reject\-shallow]
42 [\-\-filter=<filter> [\-\-also\-filter\-submodules]] [\-\-] <repository>
48 Clones a repository into a newly created directory, creates remote\-tracking branches for each branch in the cloned repository (visible using \fBgit branch \-\-remotes\fR), and creates and checks out an initial branch that is forked from the cloned repository\(cqs currently active branch\&.
50 After the clone, a plain \fBgit fetch\fR without arguments will update all the remote\-tracking branches, and a \fBgit pull\fR without arguments will in addition merge the remote master branch into the current master branch, if any (this is untrue when "\-\-single\-branch" is given; see below)\&.
52 This default configuration is achieved by creating references to the remote branch heads under \fBrefs/remotes/origin\fR and by initializing \fBremote\&.origin\&.url\fR and \fBremote\&.origin\&.fetch\fR configuration variables\&.
57 When the repository to clone from is on a local machine, this flag bypasses the normal "Git aware" transport mechanism and clones the repository by making a copy of HEAD and everything under objects and refs directories\&. The files under
59 directory are hardlinked to save space when possible\&.
61 If the repository is specified as a local path (e\&.g\&.,
62 \fB/path/to/repo\fR), this is the default, and \-\-local is essentially a no\-op\&. If the repository is specified as a URL, then this flag is ignored (and we never use the local optimizations)\&. Specifying
64 will override the default when
66 is given, using the regular Git transport instead\&.
68 \fBNOTE\fR: this operation can race with concurrent modification to the source repository, similar to running
76 Force the cloning process from a repository on a local filesystem to copy the files under the
78 directory instead of using hardlinks\&. This may be desirable if you are trying to make a back\-up of your repository\&.
83 When the repository to clone is on the local machine, instead of using hard links, automatically setup
84 \fB\&.git/objects/info/alternates\fR
85 to share the objects with the source repository\&. The resulting repository starts out without any object of its own\&.
87 \fBNOTE\fR: this is a possibly dangerous operation; do
89 use it unless you understand what it does\&. If you clone your repository using this option and then delete branches (or use any other Git command that makes any existing commit unreferenced) in the source repository, some objects may become unreferenced (or dangling)\&. These objects may be removed by normal Git operations (such as
90 \fBgit commit\fR) which automatically call
91 \fBgit maintenance run \-\-auto\fR\&. (See
92 \fBgit-maintenance\fR(1)\&.) If these objects are removed and were referenced by the cloned repository, then the cloned repository will become corrupt\&.
98 option in a repository cloned with
100 will copy objects from the source repository into a pack in the cloned repository, removing the disk space savings of
101 \fBclone \-\-shared\fR\&. It is safe, however, to run
102 \fBgit gc\fR, which uses the
106 If you want to break the dependency of a repository cloned with
108 on its source repository, you can simply run
110 to copy all objects from the source repository into a pack in the cloned repository\&.
113 \-\-reference[\-if\-able] <repository>
115 If the reference repository is on the local machine, automatically setup
116 \fB\&.git/objects/info/alternates\fR
117 to obtain objects from the reference repository\&. Using an already existing repository as an alternate will require fewer objects to be copied from the repository being cloned, reducing network and local storage costs\&. When using the
118 \fB\-\-reference\-if\-able\fR, a non existing directory is skipped with a warning instead of aborting the clone\&.
120 \fBNOTE\fR: see the NOTE for the
129 Borrow the objects from reference repositories specified with the
131 options only to reduce network transfer, and stop borrowing from them after a clone is made by making necessary local copies of borrowed objects\&. This option can also be used when cloning locally from a repository that already borrows objects from another repository\(emthe new repository will borrow objects from the same repository, and this option can be used to stop the borrowing\&.
136 Operate quietly\&. Progress is not reported to the standard error stream\&.
141 Run verbosely\&. Does not affect the reporting of progress status to the standard error stream\&.
146 Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
148 is specified\&. This flag forces progress status even if the standard error stream is not directed to a terminal\&.
151 \-\-server\-option=<option>
153 Transmit the given string to the server when communicating using protocol version 2\&. The given string must not contain a NUL or LF character\&. The server\(cqs handling of server options, including unknown ones, is server\-specific\&. When multiple
154 \fB\-\-server\-option=<option>\fR
155 are given, they are all sent to the other side in the order listed on the command line\&.
158 \-n, \-\-no\-checkout
160 No checkout of HEAD is performed after the clone is complete\&.
163 \-\-[no\-]reject\-shallow
165 Fail if the source repository is a shallow repository\&. The
166 \fIclone\&.rejectShallow\fR
167 configuration variable can be used to specify the default\&.
174 Git repository\&. That is, instead of creating
176 and placing the administrative files in
177 \fB<directory>/\&.git\fR, make the
180 \fB$GIT_DIR\fR\&. This obviously implies the
181 \fB\-\-no\-checkout\fR
182 because there is nowhere to check out the working tree\&. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to
183 \fBrefs/remotes/origin/\fR\&. When this option is used, neither remote\-tracking branches nor the related configuration variables are created\&.
188 Employ a sparse\-checkout, with only files in the toplevel directory initially being present\&. The
189 \fBgit-sparse-checkout\fR(1)
190 command can be used to grow the working directory as needed\&.
193 \-\-filter=<filter\-spec>
195 Use the partial clone feature and request that the server sends a subset of reachable objects according to a given object filter\&. When using
196 \fB\-\-filter\fR, the supplied
198 is used for the partial clone filter\&. For example,
199 \fB\-\-filter=blob:none\fR
200 will filter out all blobs (file contents) until needed by Git\&. Also,
201 \fB\-\-filter=blob:limit=<size>\fR
202 will filter out all blobs of size at least
203 \fB<size>\fR\&. For more details on filter specifications, see the
206 \fBgit-rev-list\fR(1)\&.
209 \-\-also\-filter\-submodules
211 Also apply the partial clone filter to any submodules in the repository\&. Requires
214 \fB\-\-recurse\-submodules\fR\&. This can be turned on by default by setting the
215 \fBclone\&.filterSubmodules\fR
221 Set up a mirror of the source repository\&. This implies
222 \fB\-\-bare\fR\&. Compared to
225 not only maps local branches of the source to local branches of the target, it maps all refs (including remote\-tracking branches, notes etc\&.) and sets up a refspec configuration such that all these refs are overwritten by a
226 \fBgit remote update\fR
227 in the target repository\&.
230 \-o <name>, \-\-origin <name>
232 Instead of using the remote name
234 to keep track of the upstream repository, use
235 \fB<name>\fR\&. Overrides
236 \fBclone\&.defaultRemoteName\fR
240 \-b <name>, \-\-branch <name>
242 Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository\(cqs HEAD, point to
244 branch instead\&. In a non\-bare repository, this is the branch that will be checked out\&.
246 can also take tags and detaches the HEAD at that commit in the resulting repository\&.
249 \-u <upload\-pack>, \-\-upload\-pack <upload\-pack>
251 When given, and the repository to clone from is accessed via ssh, this specifies a non\-default path for the command run on the other end\&.
254 \-\-template=<template\-directory>
256 Specify the directory from which templates will be used; (See the "TEMPLATE DIRECTORY" section of
257 \fBgit-init\fR(1)\&.)
260 \-c <key>=<value>, \-\-config <key>=<value>
262 Set a configuration variable in the newly\-created repository; this takes effect immediately after the repository is initialized, but before the remote history is fetched or any files checked out\&. The key is in the same format as expected by
265 \fBcore\&.eol=true\fR)\&. If multiple values are given for the same key, each value will be written to the config file\&. This makes it safe, for example, to add additional fetch refspecs to the origin remote\&.
267 Due to limitations of the current implementation, some configuration variables do not take effect until after the initial fetch and checkout\&. Configuration variables known to not take effect are:
268 \fBremote\&.<name>\&.mirror\fR
270 \fBremote\&.<name>\&.tagOpt\fR\&. Use the corresponding
281 clone with a history truncated to the specified number of commits\&. Implies
282 \fB\-\-single\-branch\fR
284 \fB\-\-no\-single\-branch\fR
285 is given to fetch the histories near the tips of all branches\&. If you want to clone submodules shallowly, also pass
286 \fB\-\-shallow\-submodules\fR\&.
289 \-\-shallow\-since=<date>
291 Create a shallow clone with a history after the specified time\&.
294 \-\-shallow\-exclude=<revision>
296 Create a shallow clone with a history, excluding commits reachable from a specified remote branch or tag\&. This option can be specified multiple times\&.
299 \-\-[no\-]single\-branch
301 Clone only the history leading to the tip of a single branch, either specified by the
303 option or the primary branch remote\(cqs
305 points at\&. Further fetches into the resulting repository will only update the remote\-tracking branch for the branch this option was used for the initial cloning\&. If the HEAD at the remote did not point at any branch when
306 \fB\-\-single\-branch\fR
307 clone was made, no remote\-tracking branch is created\&.
312 Don\(cqt clone any tags, and set
313 \fBremote\&.<remote>\&.tagOpt=\-\-no\-tags\fR
314 in the config, ensuring that future
318 operations won\(cqt follow any tags\&. Subsequent explicit tag fetches will still work, (see
319 \fBgit-fetch\fR(1))\&.
321 Can be used in conjunction with
322 \fB\-\-single\-branch\fR
323 to clone and maintain a branch with no references other than a single cloned branch\&. This is useful e\&.g\&. to maintain minimal clones of the default branch of some repository for search indexing\&.
326 \-\-recurse\-submodules[=<pathspec>]
328 After the clone is created, initialize and clone submodules within based on the provided pathspec\&. If no pathspec is provided, all submodules are initialized and cloned\&. This option can be given multiple times for pathspecs consisting of multiple entries\&. The resulting clone has
329 \fBsubmodule\&.active\fR
330 set to the provided pathspec, or "\&." (meaning all submodules) if no pathspec is provided\&.
332 Submodules are initialized and cloned using their default settings\&. This is equivalent to running
333 \fBgit submodule update \-\-init \-\-recursive <pathspec>\fR
334 immediately after the clone is finished\&. This option is ignored if the cloned repository does not have a worktree/checkout (i\&.e\&. if any of
335 \fB\-\-no\-checkout\fR/\fB\-n\fR,
341 \-\-[no\-]shallow\-submodules
343 All submodules which are cloned will be shallow with a depth of 1\&.
346 \-\-[no\-]remote\-submodules
348 All submodules which are cloned will use the status of the submodule\(cqs remote\-tracking branch to update the submodule, rather than the superproject\(cqs recorded SHA\-1\&. Equivalent to passing
351 \fBgit submodule update\fR\&.
354 \-\-separate\-git\-dir=<git\-dir>
356 Instead of placing the cloned repository where it is supposed to be, place the cloned repository at the specified directory, then make a filesystem\-agnostic Git symbolic link to there\&. The result is Git repository can be separated from working tree\&.
359 \-j <n>, \-\-jobs <n>
361 The number of submodules fetched at the same time\&. Defaults to the
362 \fBsubmodule\&.fetchJobs\fR
368 The (possibly remote) repository to clone from\&. See the
370 section below for more information on specifying repositories\&.
375 The name of a new directory to clone into\&. The "humanish" part of the source repository is used if no directory is explicitly given (\fBrepo\fR
377 \fB/path/to/repo\&.git\fR
381 \fBhost\&.xz:foo/\&.git\fR)\&. Cloning into an existing directory is only allowed if the directory is empty\&.
384 \-\-bundle\-uri=<uri>
386 Before fetching from the remote, fetch a bundle from the given
388 and unbundle the data into the local repository\&. The refs in the bundle will be stored under the hidden
390 namespace\&. This option is incompatible with
392 \fB\-\-shallow\-since\fR, and
393 \fB\-\-shallow\-exclude\fR\&.
397 In general, URLs contain information about the transport protocol, the address of the remote server, and the path to the repository\&. Depending on the transport protocol, some of this information may be absent\&.
399 Git supports ssh, git, http, and https protocols (in addition, ftp, and ftps can be used for fetching, but this is inefficient and deprecated; do not use it)\&.
401 The native transport (i\&.e\&. git:// URL) does no authentication and should be used with caution on unsecured networks\&.
403 The following syntaxes may be used with them:
413 ssh://[user@]host\&.xz[:port]/path/to/repo\&.git/
424 git://host\&.xz[:port]/path/to/repo\&.git/
435 http[s]://host\&.xz[:port]/path/to/repo\&.git/
446 ftp[s]://host\&.xz[:port]/path/to/repo\&.git/
449 An alternative scp\-like syntax may also be used with the ssh protocol:
459 [user@]host\&.xz:path/to/repo\&.git/
462 This syntax is only recognized if there are no slashes before the first colon\&. This helps differentiate a local path that contains a colon\&. For example the local path \fBfoo:bar\fR could be specified as an absolute path or \fB\&./foo:bar\fR to avoid being misinterpreted as an ssh url\&.
464 The ssh and git protocols additionally support ~username expansion:
474 ssh://[user@]host\&.xz[:port]/~[user]/path/to/repo\&.git/
485 git://host\&.xz[:port]/~[user]/path/to/repo\&.git/
496 [user@]host\&.xz:/~[user]/path/to/repo\&.git/
499 For local repositories, also supported by Git natively, the following syntaxes may be used:
520 file:///path/to/repo\&.git/
523 These two syntaxes are mostly equivalent, except the former implies \-\-local option\&.
525 \fIgit clone\fR, \fIgit fetch\fR and \fIgit pull\fR, but not \fIgit push\fR, will also accept a suitable bundle file\&. See \fBgit-bundle\fR(1)\&.
527 When Git doesn\(cqt know how to handle a certain transport protocol, it attempts to use the \fIremote\-<transport>\fR remote helper, if one exists\&. To explicitly request a remote helper, the following syntax may be used:
537 <transport>::<address>
540 where <address> may be a path, a server and path, or an arbitrary URL\-like string recognized by the specific remote helper being invoked\&. See \fBgitremote-helpers\fR(7) for details\&.
542 If there are a large number of similarly\-named remote repositories and you want to use a different format for them (such that the URLs you use will be rewritten into URLs that work), you can create a configuration section of the form:
548 [url "<actual url base>"]
549 insteadOf = <other url base>
556 For example, with this:
562 [url "git://git\&.host\&.xz/"]
563 insteadOf = host\&.xz:/path/to/
571 a URL like "work:repo\&.git" or like "host\&.xz:/path/to/repo\&.git" will be rewritten in any context that takes a URL to be "git://git\&.host\&.xz/repo\&.git"\&.
573 If you want to rewrite URLs for push only, you can create a configuration section of the form:
579 [url "<actual url base>"]
580 pushInsteadOf = <other url base>
587 For example, with this:
593 [url "ssh://example\&.org/"]
594 pushInsteadOf = git://example\&.org/
601 a URL like "git://example\&.org/path/to/repo\&.git" will be rewritten to "ssh://example\&.org/path/to/repo\&.git" for pushes, but pulls will still use the original URL\&.
618 $ git clone git://git\&.kernel\&.org/pub/scm/\&.\&.\&./linux\&.git my\-linux
636 Make a local clone that borrows from the current directory, without checking things out:
642 $ git clone \-l \-s \-n \&. \&.\&./copy
660 Clone from upstream while borrowing from an existing local directory:
666 $ git clone \-\-reference /git/linux\&.git \e
667 git://git\&.kernel\&.org/pub/scm/\&.\&.\&./linux\&.git \e
685 Create a bare repository to publish your changes to the public:
691 $ git clone \-\-bare \-l /home/proj/\&.git /pub/scm/proj\&.git
700 Everything below this line in this section is selectively included from the \fBgit-config\fR(1) documentation\&. The content is the same as what\(cqs found there:
704 Specify the directory from which templates will be copied\&. (See the "TEMPLATE DIRECTORY" section of
705 \fBgit-init\fR(1)\&.)
710 Allows overriding the default branch name e\&.g\&. when initializing a new repository\&.
713 clone\&.defaultRemoteName
715 The name of the remote to create when cloning a repository\&. Defaults to
716 \fBorigin\fR, and can be overridden by passing the
718 command\-line option to
719 \fBgit-clone\fR(1)\&.
722 clone\&.rejectShallow
724 Reject to clone a repository if it is a shallow one, can be overridden by passing option
725 \fB\-\-reject\-shallow\fR
726 in command line\&. See
730 clone\&.filterSubmodules
732 If a partial clone filter is provided (see
735 \fBgit-rev-list\fR(1)) and
736 \fB\-\-recurse\-submodules\fR
737 is used, also apply the filter to submodules\&.
741 Part of the \fBgit\fR(1) suite