3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.46.0.288.g3a7362eb9f
10 .TH "GIT\-CLONE" "1" "2024-08-21" "Git 2\&.46\&.0\&.288\&.g3a7362" "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 \fBgit clone\fR [\fB\-\-template=\fR\fI<template\-directory>\fR]
36 [\fB\-l\fR] [\fB\-s\fR] [\fB\-\-no\-hardlinks\fR] [\fB\-q\fR] [\fB\-n\fR] [\fB\-\-bare\fR] [\fB\-\-mirror\fR]
37 [\fB\-o\fR \fI<name>\fR] [\fB\-b\fR \fI<name>\fR] [\fB\-u\fR \fI<upload\-pack>\fR] [\fB\-\-reference\fR \fI<repository>\fR]
38 [\fB\-\-dissociate\fR] [\fB\-\-separate\-git\-dir\fR \fI<git\-dir>\fR]
39 [\fB\-\-depth\fR \fI<depth>\fR] [\fB\-\-\fR[\fBno\-\fR]\fBsingle\-branch\fR] [\fB\-\-no\-tags\fR]
40 [\fB\-\-recurse\-submodules\fR[\fB=\fR\fI<pathspec>\fR]] [\fB\-\-\fR[\fBno\-\fR]\fBshallow\-submodules\fR]
41 [\fB\-\-\fR[\fBno\-\fR]\fBremote\-submodules\fR] [\fB\-\-jobs\fR \fI<n>\fR] [\fB\-\-sparse\fR] [\fB\-\-\fR[\fBno\-\fR]\fBreject\-shallow\fR]
42 [\fB\-\-filter=\fR\fI<filter\-spec>\fR] [\fB\-\-also\-filter\-submodules\fR]] [\fB\-\-\fR] \fI<repository>\fR
47 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\&.
49 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 \fB\-\-single\-branch\fR is given; see below)\&.
51 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\&.
54 \fB\-l\fR, \fB\-\-local\fR
56 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
58 and everything under objects and refs directories\&. The files under
60 directory are hardlinked to save space when possible\&.
62 If the repository is specified as a local path (e\&.g\&.,
63 \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
65 will override the default when
67 is given, using the regular Git transport instead\&.
69 If the repository\(cqs
70 \fB$GIT_DIR/objects\fR
71 has symbolic links or is a symbolic link, the clone will fail\&. This is a security measure to prevent the unintentional copying of files by dereferencing the symbolic links\&.
73 \fBNOTE\fR: this operation can race with concurrent modification to the source repository, similar to running
79 \fB\-\-no\-hardlinks\fR
81 Force the cloning process from a repository on a local filesystem to copy the files under the
83 directory instead of using hardlinks\&. This may be desirable if you are trying to make a back\-up of your repository\&.
86 \fB\-s\fR, \fB\-\-shared\fR
88 When the repository to clone is on the local machine, instead of using hard links, automatically setup
89 \fB\&.git/objects/info/alternates\fR
90 to share the objects with the source repository\&. The resulting repository starts out without any object of its own\&.
92 \fBNOTE\fR: this is a possibly dangerous operation; do
94 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
95 \fBgit commit\fR) which automatically call
96 \fBgit maintenance run \-\-auto\fR\&. (See
97 \fBgit-maintenance\fR(1)\&.) If these objects are removed and were referenced by the cloned repository, then the cloned repository will become corrupt\&.
103 option in a repository cloned with
105 will copy objects from the source repository into a pack in the cloned repository, removing the disk space savings of
106 \fBclone \-\-shared\fR\&. It is safe, however, to run
107 \fBgit gc\fR, which uses the
111 If you want to break the dependency of a repository cloned with
113 on its source repository, you can simply run
115 to copy all objects from the source repository into a pack in the cloned repository\&.
118 \fB\-\-reference\fR[\fB\-if\-able\fR] \fI<repository>\fR
122 is on the local machine, automatically setup
123 \fB\&.git/objects/info/alternates\fR
124 to obtain objects from the reference
125 \fI<repository>\fR\&. 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
126 \fB\-\-reference\-if\-able\fR, a non existing directory is skipped with a warning instead of aborting the clone\&.
128 \fBNOTE\fR: see the NOTE for the
137 Borrow the objects from reference repositories specified with the
139 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\(em\:the new repository will borrow objects from the same repository, and this option can be used to stop the borrowing\&.
142 \fB\-q\fR, \fB\-\-quiet\fR
144 Operate quietly\&. Progress is not reported to the standard error stream\&.
147 \fB\-v\fR, \fB\-\-verbose\fR
149 Run verbosely\&. Does not affect the reporting of progress status to the standard error stream\&.
154 Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
156 is specified\&. This flag forces progress status even if the standard error stream is not directed to a terminal\&.
159 \fB\-\-server\-option=\fR\fI<option>\fR
161 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
162 \fB\-\-server\-option=\fR\fI<option>\fR
163 are given, they are all sent to the other side in the order listed on the command line\&.
166 \fB\-n\fR, \fB\-\-no\-checkout\fR
168 No checkout of HEAD is performed after the clone is complete\&.
171 \fB\-\-\fR[\fBno\-\fR]\fBreject\-shallow\fR
173 Fail if the source repository is a shallow repository\&. The
174 \fBclone\&.rejectShallow\fR
175 configuration variable can be used to specify the default\&.
182 Git repository\&. That is, instead of creating
184 and placing the administrative files in
185 \fI<directory>\fR`/\&.git`, make the
188 \fB$GIT_DIR\fR\&. This obviously implies the
189 \fB\-\-no\-checkout\fR
190 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
191 \fBrefs/remotes/origin/\fR\&. When this option is used, neither remote\-tracking branches nor the related configuration variables are created\&.
196 Employ a sparse\-checkout, with only files in the toplevel directory initially being present\&. The
197 \fBgit-sparse-checkout\fR(1)
198 command can be used to grow the working directory as needed\&.
201 \fB\-\-filter=\fR\fI<filter\-spec>\fR
203 Use the partial clone feature and request that the server sends a subset of reachable objects according to a given object filter\&. When using
204 \fB\-\-filter\fR, the supplied
206 is used for the partial clone filter\&. For example,
207 \fB\-\-filter=blob:none\fR
208 will filter out all blobs (file contents) until needed by Git\&. Also,
209 \fB\-\-filter=blob:limit=\fR\fI<size>\fR
210 will filter out all blobs of size at least
211 \fI<size>\fR\&. For more details on filter specifications, see the
214 \fBgit-rev-list\fR(1)\&.
217 \fB\-\-also\-filter\-submodules\fR
219 Also apply the partial clone filter to any submodules in the repository\&. Requires
222 \fB\-\-recurse\-submodules\fR\&. This can be turned on by default by setting the
223 \fBclone\&.filterSubmodules\fR
229 Set up a mirror of the source repository\&. This implies
230 \fB\-\-bare\fR\&. Compared to
233 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
234 \fBgit remote update\fR
235 in the target repository\&.
238 \fB\-o\fR \fI<name>\fR, \fB\-\-origin\fR \fI<name>\fR
240 Instead of using the remote name
242 to keep track of the upstream repository, use
243 \fI<name>\fR\&. Overrides
244 \fBclone\&.defaultRemoteName\fR
248 \fB\-b\fR \fI<name>\fR, \fB\-\-branch\fR \fI<name>\fR
250 Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository\(cqs HEAD, point to
252 branch instead\&. In a non\-bare repository, this is the branch that will be checked out\&.
254 can also take tags and detaches the HEAD at that commit in the resulting repository\&.
257 \fB\-u\fR \fI<upload\-pack>\fR, \fB\-\-upload\-pack\fR \fI<upload\-pack>\fR
259 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\&.
262 \fB\-\-template=\fR\fI<template\-directory>\fR
264 Specify the directory from which templates will be used; (See the "TEMPLATE DIRECTORY" section of
265 \fBgit-init\fR(1)\&.)
268 \fB\-c\fR \fI<key>\fR\fB=\fR\fI<value>\fR, \fB\-\-config\fR \fI<key>\fR\fB=\fR\fI<value>\fR
270 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
272 is in the same format as expected by
275 \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\&.
277 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:
278 \fBremote\&.\fR\fI<name>\fR\fB\&.mirror\fR
280 \fBremote\&.\fR\fI<name>\fR\fB\&.tagOpt\fR\&. Use the corresponding
287 \fB\-\-depth\fR \fI<depth>\fR
291 clone with a history truncated to the specified number of commits\&. Implies
292 \fB\-\-single\-branch\fR
294 \fB\-\-no\-single\-branch\fR
295 is given to fetch the histories near the tips of all branches\&. If you want to clone submodules shallowly, also pass
296 \fB\-\-shallow\-submodules\fR\&.
299 \fB\-\-shallow\-since=\fR\fI<date>\fR
301 Create a shallow clone with a history after the specified time\&.
304 \fB\-\-shallow\-exclude=\fR\fI<revision>\fR
306 Create a shallow clone with a history, excluding commits reachable from a specified remote branch or tag\&. This option can be specified multiple times\&.
309 \fB\-\-\fR[\fBno\-\fR]\fBsingle\-branch\fR
311 Clone only the history leading to the tip of a single branch, either specified by the
313 option or the primary branch remote\(cqs
315 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
317 at the remote did not point at any branch when
318 \fB\-\-single\-branch\fR
319 clone was made, no remote\-tracking branch is created\&.
324 Don\(cqt clone any tags, and set
325 \fBremote\&.<remote>\&.tagOpt=\-\-no\-tags\fR
326 in the config, ensuring that future
330 operations won\(cqt follow any tags\&. Subsequent explicit tag fetches will still work, (see
331 \fBgit-fetch\fR(1))\&.
333 Can be used in conjunction with
334 \fB\-\-single\-branch\fR
335 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\&.
338 \fB\-\-recurse\-submodules\fR[\fB=\fR\fI<pathspec>\fR]
340 After the clone is created, initialize and clone submodules within based on the provided
341 \fI<pathspec>\fR\&. If no
343 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
344 \fBsubmodule\&.active\fR
345 set to the provided pathspec, or "\&." (meaning all submodules) if no pathspec is provided\&.
347 Submodules are initialized and cloned using their default settings\&. This is equivalent to running
348 \fBgit submodule update \-\-init \-\-recursive <pathspec>\fR
349 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
350 \fB\-\-no\-checkout\fR/\fB\-n\fR,
356 \fB\-\-\fR[\fBno\-\fR]\fBshallow\-submodules\fR
358 All submodules which are cloned will be shallow with a depth of 1\&.
361 \fB\-\-\fR[\fBno\-\fR]\fBremote\-submodules\fR
363 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
366 \fBgit submodule update\fR\&.
369 \fB\-\-separate\-git\-dir=\fR\fI<git\-dir>\fR
371 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\&.
374 \fB\-\-ref\-format=\fR\fI<ref\-format>\fR
376 Specify the given ref storage format for the repository\&. The valid values are:
387 for loose files with packed\-refs\&. This is the default\&.
399 for the reftable format\&. This format is experimental and its internals are subject to change\&.
403 \fB\-j\fR \fI<n>\fR, \fB\-\-jobs\fR \fI<n>\fR
405 The number of submodules fetched at the same time\&. Defaults to the
406 \fBsubmodule\&.fetchJobs\fR
412 The (possibly remote)
414 to clone from\&. See the
416 section below for more information on specifying repositories\&.
421 The name of a new directory to clone into\&. The "humanish" part of the source repository is used if no
423 is explicitly given (\fBrepo\fR
425 \fB/path/to/repo\&.git\fR
429 \fBhost\&.xz:foo/\&.git\fR)\&. Cloning into an existing directory is only allowed if the directory is empty\&.
432 \fB\-\-bundle\-uri=\fR\fI<uri>\fR
434 Before fetching from the remote, fetch a bundle from the given
436 and unbundle the data into the local repository\&. The refs in the bundle will be stored under the hidden
438 namespace\&. This option is incompatible with
440 \fB\-\-shallow\-since\fR, and
441 \fB\-\-shallow\-exclude\fR\&.
445 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\&.
447 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 them)\&.
449 The native transport (i\&.e\&. git:// URL) does no authentication and should be used with caution on unsecured networks\&.
451 The following syntaxes may be used with them:
461 \fBssh://\fR[\fI<user>\fR\fB@\fR]\fI<host>\fR[\fB:\fR\fI<port>\fR]\fB/\fR\fI<path\-to\-git\-repo>\fR
472 \fBgit://\fR\fI<host>\fR[:\fI<port>\fR]\fB/\fR\fI<path\-to\-git\-repo>\fR
483 \fBhttp\fR[\fBs\fR]\fB://\fR\fI<host>\fR[\fB:\fR\fI<port>\fR]\fB/\fR\fI<path\-to\-git\-repo>\fR
494 \fBftp\fR[\fBs\fR]\fB://\fR\fI<host>\fR[\fB:\fR\fI<port>\fR]\fB/\fR\fI<path\-to\-git\-repo>\fR
497 An alternative scp\-like syntax may also be used with the ssh protocol:
507 [\fI<user>\fR\fB@\fR]\fI<host>\fR\fB:/\fR\fI<path\-to\-git\-repo>\fR
510 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\&.
512 The ssh and git protocols additionally support \fB~\fR\fI<username>\fR expansion:
522 \fBssh://\fR[\fI<user>\fR\fB@\fR]\fI<host>\fR[\fB:\fR\fI<port>\fR]\fB/~\fR\fI<user>\fR\fB/\fR\fI<path\-to\-git\-repo>\fR
533 \fBgit://\fR\fI<host>\fR[\fB:\fR\fI<port>\fR]\fB/~\fR\fI<user>\fR\fB/\fR\fI<path\-to\-git\-repo>\fR
544 [\fI<user>\fR\fB@\fR]\fI<host>\fR\fB:~\fR\fI<user>\fR\fB/\fR\fI<path\-to\-git\-repo>\fR
547 For local repositories, also supported by Git natively, the following syntaxes may be used:
557 \fB/path/to/repo\&.git/\fR
568 \fB\m[blue]\fBfile:///path/to/repo\&.git/\fR\m[]\fR
571 These two syntaxes are mostly equivalent, except the former implies \fB\-\-local\fR option\&.
573 \fBgit clone\fR, \fBgit fetch\fR and \fBgit pull\fR, but not \fBgit push\fR, will also accept a suitable bundle file\&. See \fBgit-bundle\fR(1)\&.
575 When Git doesn\(cqt know how to handle a certain transport protocol, it attempts to use the \fBremote\-\fR\fI<transport>\fR remote helper, if one exists\&. To explicitly request a remote helper, the following syntax may be used:
585 \fI<transport>\fR::\fI<address>\fR
588 where \fI<address>\fR 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\&.
590 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:
596 [url "\fI<actual\-url\-base>\fR"]
597 insteadOf = \fI<other\-url\-base>\fR
603 For example, with this:
609 [url "git://git\&.host\&.xz/"]
610 insteadOf = host\&.xz:/path/to/
617 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"\&.
619 If you want to rewrite URLs for push only, you can create a configuration section of the form:
625 [url "\fI<actual\-url\-base>\fR"]
626 pushInsteadOf = \fI<other\-url\-base>\fR
632 For example, with this:
638 [url "ssh://example\&.org/"]
639 pushInsteadOf = git://example\&.org/
645 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\&.
662 $ git clone git://git\&.kernel\&.org/pub/scm/\&.\&.\&./linux\&.git my\-linux
679 Make a local clone that borrows from the current directory, without checking things out:
685 $ git clone \-l \-s \-n \&. \&.\&./copy
702 Clone from upstream while borrowing from an existing local directory:
708 $ git clone \-\-reference /git/linux\&.git \e
709 git://git\&.kernel\&.org/pub/scm/\&.\&.\&./linux\&.git \e
726 Create a bare repository to publish your changes to the public:
732 $ git clone \-\-bare \-l /home/proj/\&.git /pub/scm/proj\&.git
740 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:
742 \fBinit\&.templateDir\fR
744 Specify the directory from which templates will be copied\&. (See the "TEMPLATE DIRECTORY" section of
745 \fBgit-init\fR(1)\&.)
748 \fBinit\&.defaultBranch\fR
750 Allows overriding the default branch name e\&.g\&. when initializing a new repository\&.
753 \fBclone\&.defaultRemoteName\fR
755 The name of the remote to create when cloning a repository\&. Defaults to
756 \fBorigin\fR\&. It can be overridden by passing the
758 command\-line option\&.
761 \fBclone\&.rejectShallow\fR
763 Reject cloning a repository if it is a shallow one; this can be overridden by passing the
764 \fB\-\-reject\-shallow\fR
765 option on the command line\&.
768 \fBclone\&.filterSubmodules\fR
770 If a partial clone filter is provided (see
773 \fBgit-rev-list\fR(1)) and
774 \fB\-\-recurse\-submodules\fR
775 is used, also apply the filter to submodules\&.
779 Part of the \fBgit\fR(1) suite