1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
\r
4 <article lang="en" id="git-clone(1)">
\r
6 <title>git-clone(1)</title>
\r
8 <primary>git-clone(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-clone - Clone a repository into a new directory</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git clone</emphasis> [--template=<template_directory>]
\r
19 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
\r
20 [-o <name>] [-u <upload-pack>] [--reference <repository>]
\r
21 [--depth <depth>] [--] <repository> [<directory>]</literallayout>
\r
24 <simplesect id="_description">
\r
25 <title>DESCRIPTION</title>
\r
26 <simpara>Clones a repository into a newly created directory, creates
\r
27 remote-tracking branches for each branch in the cloned repository
\r
28 (visible using <literal>git branch -r</literal>), and creates and checks out an initial
\r
29 branch equal to the cloned repository’s currently active branch.</simpara>
\r
30 <simpara>After the clone, a plain <literal>git fetch</literal> without arguments will update
\r
31 all the remote-tracking branches, and a <literal>git pull</literal> without
\r
32 arguments will in addition merge the remote master branch into the
\r
33 current master branch, if any.</simpara>
\r
34 <simpara>This default configuration is achieved by creating references to
\r
35 the remote branch heads under <literal>$GIT_DIR/refs/remotes/origin</literal> and
\r
36 by initializing <literal>remote.origin.url</literal> and <literal>remote.origin.fetch</literal>
\r
37 configuration variables.</simpara>
\r
39 <simplesect id="_options">
\r
40 <title>OPTIONS</title>
\r
51 When the repository to clone from is on a local machine,
\r
52 this flag bypasses normal "git aware" transport
\r
53 mechanism and clones the repository by making a copy of
\r
54 HEAD and everything under objects and refs directories.
\r
55 The files under <literal>.git/objects/</literal> directory are hardlinked
\r
56 to save space when possible. This is now the default when
\r
57 the source repository is specified with <literal>/path/to/repo</literal>
\r
58 syntax, so it essentially is a no-op option. To force
\r
59 copying instead of hardlinking (which may be desirable
\r
60 if you are trying to make a back-up of your repository),
\r
61 but still avoid the usual "git aware" transport
\r
62 mechanism, <literal>--no-hardlinks</literal> can be used.
\r
72 Optimize the cloning process from a repository on a
\r
73 local filesystem by copying files under <literal>.git/objects</literal>
\r
87 When the repository to clone is on the local machine,
\r
88 instead of using hard links, automatically setup
\r
89 .git/objects/info/alternates to share the objects
\r
90 with the source repository. The resulting repository
\r
91 starts out without any object of its own.
\r
93 <simpara><emphasis role="strong">NOTE</emphasis>: this is a possibly dangerous operation; do <emphasis role="strong">not</emphasis> use
\r
94 it unless you understand what it does. If you clone your
\r
95 repository using this option and then delete branches (or use any
\r
96 other git command that makes any existing commit unreferenced) in the
\r
97 source repository, some objects may become unreferenced (or dangling).
\r
98 These objects may be removed by normal git operations (such as <emphasis>git-commit</emphasis>)
\r
99 which automatically call <literal>git gc --auto</literal>. (See <xref linkend="git-gc(1)"/>.)
\r
100 If these objects are removed and were referenced by the cloned repository,
\r
101 then the cloned repository will become corrupt.</simpara>
\r
106 --reference <repository>
\r
110 If the reference repository is on the local machine
\r
111 automatically setup .git/objects/info/alternates to
\r
112 obtain objects from the reference repository. Using
\r
113 an already existing repository as an alternate will
\r
114 require fewer objects to be copied from the repository
\r
115 being cloned, reducing network and local storage costs.
\r
117 <simpara><emphasis role="strong">NOTE</emphasis>: see NOTE to --shared option.</simpara>
\r
129 Operate quietly. This flag is also passed to the ‘rsync’
\r
130 command when given.
\r
143 Display the progressbar, even in case the standard output is not
\r
157 No checkout of HEAD is performed after the clone is complete.
\r
167 Make a <emphasis>bare</emphasis> GIT repository. That is, instead of
\r
168 creating <literal><directory></literal> and placing the administrative
\r
169 files in <literal><directory>/.git</literal>, make the <literal><directory></literal>
\r
170 itself the <literal>$GIT_DIR</literal>. This obviously implies the <literal>-n</literal>
\r
171 because there is nowhere to check out the working tree.
\r
172 Also the branch heads at the remote are copied directly
\r
173 to corresponding local branch heads, without mapping
\r
174 them to <literal>refs/remotes/origin/</literal>. When this option is
\r
175 used, neither remote-tracking branches nor the related
\r
176 configuration variables are created.
\r
186 Set up a mirror of the remote repository. This implies --bare.
\r
192 --origin <name>
\r
199 Instead of using the remote name <emphasis>origin</emphasis> to keep track
\r
200 of the upstream repository, use <name> instead.
\r
206 --upload-pack <upload-pack>
\r
209 -u <upload-pack>
\r
213 When given, and the repository to clone from is accessed
\r
214 via ssh, this specifies a non-default path for the command
\r
215 run on the other end.
\r
221 --template=<template_directory>
\r
225 Specify the directory from which templates will be used;
\r
226 if unset the templates are taken from the installation
\r
227 defined default, typically <literal>/usr/share/git-core/templates</literal>.
\r
233 --depth <depth>
\r
237 Create a <emphasis>shallow</emphasis> clone with a history truncated to the
\r
238 specified number of revisions. A shallow repository has a
\r
239 number of limitations (you cannot clone or fetch from
\r
240 it, nor push from nor into it), but is adequate if you
\r
241 are only interested in the recent history of a large project
\r
242 with a long history, and would want to send in fixes
\r
253 The (possibly remote) repository to clone from. See the
\r
254 <link linkend="URLS">URLS</link> section below for more information on specifying
\r
265 The name of a new directory to clone into. The "humanish"
\r
266 part of the source repository is used if no directory is
\r
267 explicitly given ("repo" for "/path/to/repo.git" and "foo"
\r
268 for "host.xz:foo/.git"). Cloning into an existing directory
\r
275 <simplesect id="_git_urls_anchor_id_urls_xreflabel_urls">
\r
276 <title>GIT URLS<anchor id="URLS" xreflabel="[URLS]"/></title>
\r
277 <simpara>One of the following notations can be used
\r
278 to name the remote repository:</simpara>
\r
283 rsync://host.xz/path/to/repo.git/
\r
288 <ulink url="http://host.xz[:port]/path/to/repo.git/">http://host.xz[:port]/path/to/repo.git/</ulink>
\r
293 <ulink url="https://host.xz[:port]/path/to/repo.git/">https://host.xz[:port]/path/to/repo.git/</ulink>
\r
298 git://host.xz[:port]/path/to/repo.git/
\r
303 git://host.xz[:port]/~user/path/to/repo.git/
\r
308 ssh://[user@]host.xz[:port]/path/to/repo.git/
\r
313 ssh://[user@]host.xz/path/to/repo.git/
\r
318 ssh://[user@]host.xz/~user/path/to/repo.git/
\r
323 ssh://[user@]host.xz/~/path/to/repo.git
\r
328 <simpara>SSH is the default transport protocol over the network. You can
\r
329 optionally specify which user to log-in as, and an alternate,
\r
330 scp-like syntax is also supported. Both syntaxes support
\r
331 username expansion, as does the native git protocol, but
\r
332 only the former supports port specification. The following
\r
333 three are identical to the last three above, respectively:</simpara>
\r
338 [user@]host.xz:/path/to/repo.git/
\r
343 [user@]host.xz:~user/path/to/repo.git/
\r
348 [user@]host.xz:path/to/repo.git
\r
353 <simpara>To sync with a local directory, you can use:</simpara>
\r
363 <ulink url="file:///path/to/repo.git/">file:///path/to/repo.git/</ulink>
\r
368 <simpara>They are equivalent, except the former implies --local option.</simpara>
\r
369 <simpara>If there are a large number of similarly-named remote repositories and
\r
370 you want to use a different format for them (such that the URLs you
\r
371 use will be rewritten into URLs that work), you can create a
\r
372 configuration section of the form:</simpara>
\r
373 <literallayout> [url "<actual url base>"]
\r
374 insteadOf = <other url base></literallayout>
\r
375 <simpara>For example, with this:</simpara>
\r
376 <literallayout> [url "git://git.host.xz/"]
\r
377 insteadOf = host.xz:/path/to/
\r
378 insteadOf = work:</literallayout>
\r
379 <simpara>a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
\r
380 rewritten in any context that takes a URL to be "git://git.host.xz/repo.git".</simpara>
\r
382 <simplesect id="_examples">
\r
383 <title>Examples</title>
\r
387 Clone from upstream
\r
390 <literallayout>$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
\r
392 $ make</literallayout>
\r
397 Make a local clone that borrows from the current directory, without checking things out
\r
400 <literallayout>$ git clone -l -s -n . ../copy
\r
402 $ git show-branch</literallayout>
\r
407 Clone from upstream while borrowing from an existing local directory
\r
410 <literallayout>$ git clone --reference my2.6 \
\r
411 git://git.kernel.org/pub/scm/.../linux-2.7 \
\r
413 $ cd my2.7</literallayout>
\r
418 Create a bare repository to publish your changes to the public
\r
421 <literallayout>$ git clone --bare -l /home/proj/.git /pub/scm/proj.git</literallayout>
\r
426 Create a repository on the kernel.org machine that borrows from Linus
\r
429 <literallayout>$ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \
\r
430 /pub/scm/.../me/subsys-2.6.git</literallayout>
\r
435 <simplesect id="_author">
\r
436 <title>Author</title>
\r
437 <simpara>Written by Linus Torvalds <<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>></simpara>
\r
439 <simplesect id="_documentation">
\r
440 <title>Documentation</title>
\r
441 <simpara>Documentation by Junio C Hamano and the git-list <<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>>.</simpara>
\r
443 <simplesect id="_git">
\r
445 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
\r