1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <sect2 lang="en" id="git-clone(1)">
\r
5 <title>git-clone(1)</title>
\r
7 <primary>git-clone(1)</primary>
\r
9 <simplesect id="git-clone(1)__name">
\r
11 <simpara>git-clone - Clone a repository into a new directory</simpara>
\r
13 <simplesect id="git-clone(1)__synopsis">
\r
14 <title>SYNOPSIS</title>
\r
16 <literallayout><emphasis>git clone</emphasis> [--template=<template_directory>]
\r
17 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
\r
18 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
\r
19 [--separate-git-dir <git dir>]
\r
20 [--depth <depth>] [--[no-]single-branch]
\r
21 [--recursive|--recurse-submodules] [--] <repository>
\r
22 [<directory>]</literallayout>
\r
25 <simplesect id="git-clone(1)__description">
\r
26 <title>DESCRIPTION</title>
\r
27 <simpara>Clones a repository into a newly created directory, creates
\r
28 remote-tracking branches for each branch in the cloned repository
\r
29 (visible using <emphasis>git branch -r</emphasis>), and creates and checks out an
\r
30 initial branch that is forked from the cloned repository's
\r
31 currently active branch.</simpara>
\r
32 <simpara>After the clone, a plain <emphasis>git fetch</emphasis> without arguments will update
\r
33 all the remote-tracking branches, and a <emphasis>git pull</emphasis> without
\r
34 arguments will in addition merge the remote master branch into the
\r
35 current master branch, if any (this is untrue when "--single-branch"
\r
36 is given; see below).</simpara>
\r
37 <simpara>This default configuration is achieved by creating references to
\r
38 the remote branch heads under <emphasis>refs/remotes/origin</emphasis> and
\r
39 by initializing <emphasis>remote.origin.url</emphasis> and <emphasis>remote.origin.fetch</emphasis>
\r
40 configuration variables.</simpara>
\r
42 <simplesect id="git-clone(1)__options">
\r
43 <title>OPTIONS</title>
\r
54 When the repository to clone from is on a local machine,
\r
55 this flag bypasses the normal "git aware" transport
\r
56 mechanism and clones the repository by making a copy of
\r
57 HEAD and everything under objects and refs directories.
\r
58 The files under <emphasis>.git/objects/</emphasis> directory are hardlinked
\r
59 to save space when possible.
\r
61 <simpara>If the repository is specified as a local path (e.g., <emphasis>/path/to/repo</emphasis>),
\r
62 this is the default, and --local is essentially a no-op. If the
\r
63 repository is specified as a URL, then this flag is ignored (and we
\r
64 never use the local optimizations). Specifying <emphasis>--no-local</emphasis> will
\r
65 override the default when <emphasis>/path/to/repo</emphasis> is given, using the regular
\r
66 git transport instead.</simpara>
\r
67 <simpara>To force copying instead of hardlinking (which may be desirable if you
\r
68 are trying to make a back-up of your repository), but still avoid the
\r
69 usual "git aware" transport mechanism, <emphasis>--no-hardlinks</emphasis> can be used.</simpara>
\r
78 Optimize the cloning process from a repository on a
\r
79 local filesystem by copying files under <emphasis>.git/objects</emphasis>
\r
93 When the repository to clone is on the local machine,
\r
94 instead of using hard links, automatically setup
\r
95 <emphasis>.git/objects/info/alternates</emphasis> to share the objects
\r
96 with the source repository. The resulting repository
\r
97 starts out without any object of its own.
\r
99 <simpara><emphasis role="strong">NOTE</emphasis>: this is a possibly dangerous operation; do <emphasis role="strong">not</emphasis> use
\r
100 it unless you understand what it does. If you clone your
\r
101 repository using this option and then delete branches (or use any
\r
102 other git command that makes any existing commit unreferenced) in the
\r
103 source repository, some objects may become unreferenced (or dangling).
\r
104 These objects may be removed by normal git operations (such as <emphasis>git commit</emphasis>)
\r
105 which automatically call <emphasis>git gc --auto</emphasis>. (See <xref linkend="git-gc(1)" />.)
\r
106 If these objects are removed and were referenced by the cloned repository,
\r
107 then the cloned repository will become corrupt.</simpara>
\r
108 <simpara>Note that running <emphasis>git repack</emphasis> without the <emphasis>-l</emphasis> option in a repository
\r
109 cloned with <emphasis>-s</emphasis> will copy objects from the source repository into a pack
\r
110 in the cloned repository, removing the disk space savings of <emphasis>clone -s</emphasis>.
\r
111 It is safe, however, to run <emphasis>git gc</emphasis>, which uses the <emphasis>-l</emphasis> option by
\r
113 <simpara>If you want to break the dependency of a repository cloned with <emphasis>-s</emphasis> on
\r
114 its source repository, you can simply run <emphasis>git repack -a</emphasis> to copy all
\r
115 objects from the source repository into a pack in the cloned repository.</simpara>
\r
120 --reference <repository>
\r
124 If the reference repository is on the local machine,
\r
125 automatically setup <emphasis>.git/objects/info/alternates</emphasis> to
\r
126 obtain objects from the reference repository. Using
\r
127 an already existing repository as an alternate will
\r
128 require fewer objects to be copied from the repository
\r
129 being cloned, reducing network and local storage costs.
\r
131 <simpara><emphasis role="strong">NOTE</emphasis>: see the NOTE for the <emphasis>--shared</emphasis> option.</simpara>
\r
143 Operate quietly. Progress is not reported to the standard
\r
144 error stream. This flag is also passed to the rsync
\r
145 command when given.
\r
158 Run verbosely. Does not affect the reporting of progress status
\r
159 to the standard error stream.
\r
169 Progress status is reported on the standard error stream
\r
170 by default when it is attached to a terminal, unless -q
\r
171 is specified. This flag forces progress status even if the
\r
172 standard error stream is not directed to a terminal.
\r
185 No checkout of HEAD is performed after the clone is complete.
\r
195 Make a <emphasis>bare</emphasis> GIT repository. That is, instead of
\r
196 creating <emphasis><directory></emphasis> and placing the administrative
\r
197 files in <emphasis><directory>/.git</emphasis>, make the <emphasis><directory></emphasis>
\r
198 itself the <emphasis>$GIT_DIR</emphasis>. This obviously implies the <emphasis>-n</emphasis>
\r
199 because there is nowhere to check out the working tree.
\r
200 Also the branch heads at the remote are copied directly
\r
201 to corresponding local branch heads, without mapping
\r
202 them to <emphasis>refs/remotes/origin/</emphasis>. When this option is
\r
203 used, neither remote-tracking branches nor the related
\r
204 configuration variables are created.
\r
214 Set up a mirror of the source repository. This implies <emphasis>--bare</emphasis>.
\r
215 Compared to <emphasis>--bare</emphasis>, <emphasis>--mirror</emphasis> not only maps local branches of the
\r
216 source to local branches of the target, it maps all refs (including
\r
217 remote-tracking branches, notes etc.) and sets up a refspec configuration such
\r
218 that all these refs are overwritten by a <emphasis>git remote update</emphasis> in the
\r
225 --origin <name>
\r
232 Instead of using the remote name <emphasis>origin</emphasis> to keep track
\r
233 of the upstream repository, use <emphasis><name></emphasis>.
\r
239 --branch <name>
\r
246 Instead of pointing the newly created HEAD to the branch pointed
\r
247 to by the cloned repository's HEAD, point to <emphasis><name></emphasis> branch
\r
248 instead. In a non-bare repository, this is the branch that will
\r
250 <emphasis>--branch</emphasis> can also take tags and detaches the HEAD at that commit
\r
251 in the resulting repository.
\r
257 --upload-pack <upload-pack>
\r
260 -u <upload-pack>
\r
264 When given, and the repository to clone from is accessed
\r
265 via ssh, this specifies a non-default path for the command
\r
266 run on the other end.
\r
272 --template=<template_directory>
\r
276 Specify the directory from which templates will be used;
\r
277 (See the "TEMPLATE DIRECTORY" section of <xref linkend="git-init(1)" />.)
\r
283 --config <key>=<value>
\r
286 -c <key>=<value>
\r
290 Set a configuration variable in the newly-created repository;
\r
291 this takes effect immediately after the repository is
\r
292 initialized, but before the remote history is fetched or any
\r
293 files checked out. The key is in the same format as expected by
\r
294 <xref linkend="git-config(1)" /> (e.g., <emphasis>core.eol=true</emphasis>). If multiple
\r
295 values are given for the same key, each value will be written to
\r
296 the config file. This makes it safe, for example, to add
\r
297 additional fetch refspecs to the origin remote.
\r
303 --depth <depth>
\r
307 Create a <emphasis>shallow</emphasis> clone with a history truncated to the
\r
308 specified number of revisions. A shallow repository has a
\r
309 number of limitations (you cannot clone or fetch from
\r
310 it, nor push from nor into it), but is adequate if you
\r
311 are only interested in the recent history of a large project
\r
312 with a long history, and would want to send in fixes
\r
323 Clone only the history leading to the tip of a single branch,
\r
324 either specified by the <emphasis>--branch</emphasis> option or the primary
\r
325 branch remote's <emphasis>HEAD</emphasis> points at. When creating a shallow
\r
326 clone with the <emphasis>--depth</emphasis> option, this is the default, unless
\r
327 <emphasis>--no-single-branch</emphasis> is given to fetch the histories near the
\r
328 tips of all branches.
\r
329 Further fetches into the resulting repository will only update the
\r
330 remote-tracking branch for the branch this option was used for the
\r
331 initial cloning. If the HEAD at the remote did not point at any
\r
332 branch when <emphasis>--single-branch</emphasis> clone was made, no remote-tracking
\r
342 --recurse-submodules
\r
346 After the clone is created, initialize all submodules within,
\r
347 using their default settings. This is equivalent to running
\r
348 <emphasis>git submodule update --init --recursive</emphasis> immediately after
\r
349 the clone is finished. This option is ignored if the cloned
\r
350 repository does not have a worktree/checkout (i.e. if any of
\r
351 <emphasis>--no-checkout</emphasis>/<emphasis>-n</emphasis>, <emphasis>--bare</emphasis>, or <emphasis>--mirror</emphasis> is given)
\r
357 --separate-git-dir=<git dir>
\r
361 Instead of placing the cloned repository where it is supposed
\r
362 to be, place the cloned repository at the specified directory,
\r
363 then make a filesytem-agnostic git symbolic link to there.
\r
364 The result is git repository can be separated from working
\r
375 The (possibly remote) repository to clone from. See the
\r
376 <link linkend="git-clone(1)_URLS">URLS</link> section below for more information on specifying
\r
387 The name of a new directory to clone into. The "humanish"
\r
388 part of the source repository is used if no directory is
\r
389 explicitly given (<emphasis>repo</emphasis> for <emphasis>/path/to/repo.git</emphasis> and <emphasis>foo</emphasis>
\r
390 for <emphasis>host.xz:foo/.git</emphasis>). Cloning into an existing directory
\r
391 is only allowed if the directory is empty.
\r
397 <simplesect id="git-clone(1)__git_urls_anchor_id_git_clone_1__urls_xreflabel_urls">
\r
398 <title>GIT URLS<anchor id="git-clone(1)_URLS" xreflabel="[URLS]"/></title>
\r
399 <simpara>In general, URLs contain information about the transport protocol, the
\r
400 address of the remote server, and the path to the repository.
\r
401 Depending on the transport protocol, some of this information may be
\r
403 <simpara>Git supports ssh, git, http, and https protocols (in addition, ftp,
\r
404 and ftps can be used for fetching and rsync can be used for fetching
\r
405 and pushing, but these are inefficient and deprecated; do not use
\r
407 <simpara>The following syntaxes may be used with them:</simpara>
\r
411 ssh://[user@]host.xz[:port]/path/to/repo.git/
\r
416 git://host.xz[:port]/path/to/repo.git/
\r
421 http[s]://host.xz[:port]/path/to/repo.git/
\r
426 ftp[s]://host.xz[:port]/path/to/repo.git/
\r
431 rsync://host.xz/path/to/repo.git/
\r
435 <simpara>An alternative scp-like syntax may also be used with the ssh protocol:</simpara>
\r
439 [user@]host.xz:path/to/repo.git/
\r
443 <simpara>The ssh and git protocols additionally support ~username expansion:</simpara>
\r
447 ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
\r
452 git://host.xz[:port]/~[user]/path/to/repo.git/
\r
457 [user@]host.xz:/~[user]/path/to/repo.git/
\r
461 <simpara>For local repositories, also supported by git natively, the following
\r
462 syntaxes may be used:</simpara>
\r
471 <ulink url="file:///path/to/repo.git/">file:///path/to/repo.git/</ulink>
\r
475 <simpara>These two syntaxes are mostly equivalent, except the former implies
\r
476 --local option.</simpara>
\r
477 <simpara>When git doesn't know how to handle a certain transport protocol, it
\r
478 attempts to use the <emphasis>remote-<transport></emphasis> remote helper, if one
\r
479 exists. To explicitly request a remote helper, the following syntax
\r
480 may be used:</simpara>
\r
484 <transport>::<address>
\r
488 <simpara>where <address> may be a path, a server and path, or an arbitrary
\r
489 URL-like string recognized by the specific remote helper being
\r
490 invoked. See <xref linkend="git-remote-helpers(1)" /> for details.</simpara>
\r
491 <simpara>If there are a large number of similarly-named remote repositories and
\r
492 you want to use a different format for them (such that the URLs you
\r
493 use will be rewritten into URLs that work), you can create a
\r
494 configuration section of the form:</simpara>
\r
495 <screen> [url "<actual url base>"]
\r
496 insteadOf = <other url base></screen>
\r
497 <simpara>For example, with this:</simpara>
\r
498 <screen> [url "git://git.host.xz/"]
\r
499 insteadOf = host.xz:/path/to/
\r
500 insteadOf = work:</screen>
\r
501 <simpara>a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
\r
502 rewritten in any context that takes a URL to be "git://git.host.xz/repo.git".</simpara>
\r
503 <simpara>If you want to rewrite URLs for push only, you can create a
\r
504 configuration section of the form:</simpara>
\r
505 <screen> [url "<actual url base>"]
\r
506 pushInsteadOf = <other url base></screen>
\r
507 <simpara>For example, with this:</simpara>
\r
508 <screen> [url "ssh://example.org/"]
\r
509 pushInsteadOf = git://example.org/</screen>
\r
510 <simpara>a URL like "git://example.org/path/to/repo.git" will be rewritten to
\r
511 "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
\r
512 use the original URL.</simpara>
\r
514 <simplesect id="git-clone(1)__examples">
\r
515 <title>Examples</title>
\r
519 Clone from upstream:
\r
521 <screen>$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
\r
527 Make a local clone that borrows from the current directory, without checking things out:
\r
529 <screen>$ git clone -l -s -n . ../copy
\r
531 $ git show-branch</screen>
\r
535 Clone from upstream while borrowing from an existing local directory:
\r
537 <screen>$ git clone --reference my2.6 \
\r
538 git://git.kernel.org/pub/scm/.../linux-2.7 \
\r
540 $ cd my2.7</screen>
\r
544 Create a bare repository to publish your changes to the public:
\r
546 <screen>$ git clone --bare -l /home/proj/.git /pub/scm/proj.git</screen>
\r
550 Create a repository on the kernel.org machine that borrows from Linus:
\r
552 <screen>$ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \
\r
553 /pub/scm/.../me/subsys-2.6.git</screen>
\r
557 <simplesect id="git-clone(1)__git">
\r
559 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r