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.35.1.225.ge2ac9141e6
10 .TH "GIT\-CLONE" "1" "02/17/2022" "Git 2\&.35\&.1\&.225\&.ge2ac91" "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>] [\-\-] <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)\&.
211 Set up a mirror of the source repository\&. This implies
212 \fB\-\-bare\fR\&. Compared to
215 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
216 \fBgit remote update\fR
217 in the target repository\&.
220 \-o <name>, \-\-origin <name>
222 Instead of using the remote name
224 to keep track of the upstream repository, use
225 \fB<name>\fR\&. Overrides
226 \fBclone\&.defaultRemoteName\fR
230 \-b <name>, \-\-branch <name>
232 Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository\(cqs HEAD, point to
234 branch instead\&. In a non\-bare repository, this is the branch that will be checked out\&.
236 can also take tags and detaches the HEAD at that commit in the resulting repository\&.
239 \-u <upload\-pack>, \-\-upload\-pack <upload\-pack>
241 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\&.
244 \-\-template=<template\-directory>
246 Specify the directory from which templates will be used; (See the "TEMPLATE DIRECTORY" section of
247 \fBgit-init\fR(1)\&.)
250 \-c <key>=<value>, \-\-config <key>=<value>
252 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
255 \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\&.
257 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:
258 \fBremote\&.<name>\&.mirror\fR
260 \fBremote\&.<name>\&.tagOpt\fR\&. Use the corresponding
271 clone with a history truncated to the specified number of commits\&. Implies
272 \fB\-\-single\-branch\fR
274 \fB\-\-no\-single\-branch\fR
275 is given to fetch the histories near the tips of all branches\&. If you want to clone submodules shallowly, also pass
276 \fB\-\-shallow\-submodules\fR\&.
279 \-\-shallow\-since=<date>
281 Create a shallow clone with a history after the specified time\&.
284 \-\-shallow\-exclude=<revision>
286 Create a shallow clone with a history, excluding commits reachable from a specified remote branch or tag\&. This option can be specified multiple times\&.
289 \-\-[no\-]single\-branch
291 Clone only the history leading to the tip of a single branch, either specified by the
293 option or the primary branch remote\(cqs
295 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
296 \fB\-\-single\-branch\fR
297 clone was made, no remote\-tracking branch is created\&.
302 Don\(cqt clone any tags, and set
303 \fBremote\&.<remote>\&.tagOpt=\-\-no\-tags\fR
304 in the config, ensuring that future
308 operations won\(cqt follow any tags\&. Subsequent explicit tag fetches will still work, (see
309 \fBgit-fetch\fR(1))\&.
311 Can be used in conjunction with
312 \fB\-\-single\-branch\fR
313 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\&.
316 \-\-recurse\-submodules[=<pathspec>]
318 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
319 \fBsubmodule\&.active\fR
320 set to the provided pathspec, or "\&." (meaning all submodules) if no pathspec is provided\&.
322 Submodules are initialized and cloned using their default settings\&. This is equivalent to running
323 \fBgit submodule update \-\-init \-\-recursive <pathspec>\fR
324 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
325 \fB\-\-no\-checkout\fR/\fB\-n\fR,
331 \-\-[no\-]shallow\-submodules
333 All submodules which are cloned will be shallow with a depth of 1\&.
336 \-\-[no\-]remote\-submodules
338 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
341 \fBgit submodule update\fR\&.
344 \-\-separate\-git\-dir=<git\-dir>
346 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\&.
349 \-j <n>, \-\-jobs <n>
351 The number of submodules fetched at the same time\&. Defaults to the
352 \fBsubmodule\&.fetchJobs\fR
358 The (possibly remote) repository to clone from\&. See the
360 section below for more information on specifying repositories\&.
365 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
367 \fB/path/to/repo\&.git\fR
371 \fBhost\&.xz:foo/\&.git\fR)\&. Cloning into an existing directory is only allowed if the directory is empty\&.
375 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\&.
377 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)\&.
379 The native transport (i\&.e\&. git:// URL) does no authentication and should be used with caution on unsecured networks\&.
381 The following syntaxes may be used with them:
391 ssh://[user@]host\&.xz[:port]/path/to/repo\&.git/
402 git://host\&.xz[:port]/path/to/repo\&.git/
413 http[s]://host\&.xz[:port]/path/to/repo\&.git/
424 ftp[s]://host\&.xz[:port]/path/to/repo\&.git/
427 An alternative scp\-like syntax may also be used with the ssh protocol:
437 [user@]host\&.xz:path/to/repo\&.git/
440 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\&.
442 The ssh and git protocols additionally support ~username expansion:
452 ssh://[user@]host\&.xz[:port]/~[user]/path/to/repo\&.git/
463 git://host\&.xz[:port]/~[user]/path/to/repo\&.git/
474 [user@]host\&.xz:/~[user]/path/to/repo\&.git/
477 For local repositories, also supported by Git natively, the following syntaxes may be used:
498 file:///path/to/repo\&.git/
501 These two syntaxes are mostly equivalent, except the former implies \-\-local option\&.
503 \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)\&.
505 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:
515 <transport>::<address>
518 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\&.
520 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:
526 [url "<actual url base>"]
527 insteadOf = <other url base>
534 For example, with this:
540 [url "git://git\&.host\&.xz/"]
541 insteadOf = host\&.xz:/path/to/
549 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"\&.
551 If you want to rewrite URLs for push only, you can create a configuration section of the form:
557 [url "<actual url base>"]
558 pushInsteadOf = <other url base>
565 For example, with this:
571 [url "ssh://example\&.org/"]
572 pushInsteadOf = git://example\&.org/
579 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\&.
596 $ git clone git://git\&.kernel\&.org/pub/scm/\&.\&.\&./linux\&.git my\-linux
614 Make a local clone that borrows from the current directory, without checking things out:
620 $ git clone \-l \-s \-n \&. \&.\&./copy
638 Clone from upstream while borrowing from an existing local directory:
644 $ git clone \-\-reference /git/linux\&.git \e
645 git://git\&.kernel\&.org/pub/scm/\&.\&.\&./linux\&.git \e
663 Create a bare repository to publish your changes to the public:
669 $ git clone \-\-bare \-l /home/proj/\&.git /pub/scm/proj\&.git
678 Part of the \fBgit\fR(1) suite