updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-clone.xml
blobc65b4793a106f5e9fb2b6d7985e65dcb9d19e0b4
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-clone(1)">\r
5 <articleinfo>\r
6     <title>git-clone(1)</title>\r
7 <indexterm>\r
8 <primary>git-clone(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-clone - Clone a repository into a new directory</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git clone</emphasis> [--template=&lt;template_directory&gt;]\r
19           [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]\r
20           [-o &lt;name&gt;] [-b &lt;name&gt;] [-u &lt;upload-pack&gt;] [--reference &lt;repository&gt;]\r
21           [--separate-git-dir &lt;git dir&gt;]\r
22           [--depth &lt;depth&gt;] [--[no-]single-branch]\r
23           [--recursive|--recurse-submodules] [--] &lt;repository&gt;\r
24           [&lt;directory&gt;]</literallayout>\r
25 </blockquote>\r
26 </simplesect>\r
27 <simplesect id="_description">\r
28 <title>DESCRIPTION</title>\r
29 <simpara>Clones a repository into a newly created directory, creates\r
30 remote-tracking branches for each branch in the cloned repository\r
31 (visible using <emphasis>git branch -r</emphasis>), and creates and checks out an\r
32 initial branch that is forked from the cloned repository's\r
33 currently active branch.</simpara>\r
34 <simpara>After the clone, a plain <emphasis>git fetch</emphasis> without arguments will update\r
35 all the remote-tracking branches, and a <emphasis>git pull</emphasis> without\r
36 arguments will in addition merge the remote master branch into the\r
37 current master branch, if any.</simpara>\r
38 <simpara>This default configuration is achieved by creating references to\r
39 the remote branch heads under <emphasis>refs/remotes/origin</emphasis> and\r
40 by initializing <emphasis>remote.origin.url</emphasis> and <emphasis>remote.origin.fetch</emphasis>\r
41 configuration variables.</simpara>\r
42 </simplesect>\r
43 <simplesect id="_options">\r
44 <title>OPTIONS</title>\r
45 <variablelist>\r
46 <varlistentry>\r
47 <term>\r
48 --local\r
49 </term>\r
50 <term>\r
51 -l\r
52 </term>\r
53 <listitem>\r
54 <simpara>\r
55         When the repository to clone from is on a local machine,\r
56         this flag bypasses the normal "git aware" transport\r
57         mechanism and clones the repository by making a copy of\r
58         HEAD and everything under objects and refs directories.\r
59         The files under <emphasis>.git/objects/</emphasis> directory are hardlinked\r
60         to save space when possible.  This is now the default when\r
61         the source repository is specified with <emphasis>/path/to/repo</emphasis>\r
62         syntax, so it essentially is a no-op option.  To force\r
63         copying instead of hardlinking (which may be desirable\r
64         if you are trying to make a back-up of your repository),\r
65         but still avoid the usual "git aware" transport\r
66         mechanism, <emphasis>--no-hardlinks</emphasis> can be used.\r
67 </simpara>\r
68 </listitem>\r
69 </varlistentry>\r
70 <varlistentry>\r
71 <term>\r
72 --no-hardlinks\r
73 </term>\r
74 <listitem>\r
75 <simpara>\r
76         Optimize the cloning process from a repository on a\r
77         local filesystem by copying files under <emphasis>.git/objects</emphasis>\r
78         directory.\r
79 </simpara>\r
80 </listitem>\r
81 </varlistentry>\r
82 <varlistentry>\r
83 <term>\r
84 --shared\r
85 </term>\r
86 <term>\r
87 -s\r
88 </term>\r
89 <listitem>\r
90 <simpara>\r
91         When the repository to clone is on the local machine,\r
92         instead of using hard links, automatically setup\r
93         <emphasis>.git/objects/info/alternates</emphasis> to share the objects\r
94         with the source repository.  The resulting repository\r
95         starts out without any object of its own.\r
96 </simpara>\r
97 <simpara><emphasis role="strong">NOTE</emphasis>: this is a possibly dangerous operation; do <emphasis role="strong">not</emphasis> use\r
98 it unless you understand what it does. If you clone your\r
99 repository using this option and then delete branches (or use any\r
100 other git command that makes any existing commit unreferenced) in the\r
101 source repository, some objects may become unreferenced (or dangling).\r
102 These objects may be removed by normal git operations (such as <emphasis>git commit</emphasis>)\r
103 which automatically call <emphasis>git gc --auto</emphasis>. (See <xref linkend="git-gc(1)" />.)\r
104 If these objects are removed and were referenced by the cloned repository,\r
105 then the cloned repository will become corrupt.</simpara>\r
106 <simpara>Note that running <emphasis>git repack</emphasis> without the <emphasis>-l</emphasis> option in a repository\r
107 cloned with <emphasis>-s</emphasis> will copy objects from the source repository into a pack\r
108 in the cloned repository, removing the disk space savings of <emphasis>clone -s</emphasis>.\r
109 It is safe, however, to run <emphasis>git gc</emphasis>, which uses the <emphasis>-l</emphasis> option by\r
110 default.</simpara>\r
111 <simpara>If you want to break the dependency of a repository cloned with <emphasis>-s</emphasis> on\r
112 its source repository, you can simply run <emphasis>git repack -a</emphasis> to copy all\r
113 objects from the source repository into a pack in the cloned repository.</simpara>\r
114 </listitem>\r
115 </varlistentry>\r
116 <varlistentry>\r
117 <term>\r
118 --reference &lt;repository&gt;\r
119 </term>\r
120 <listitem>\r
121 <simpara>\r
122         If the reference repository is on the local machine,\r
123         automatically setup <emphasis>.git/objects/info/alternates</emphasis> to\r
124         obtain objects from the reference repository.  Using\r
125         an already existing repository as an alternate will\r
126         require fewer objects to be copied from the repository\r
127         being cloned, reducing network and local storage costs.\r
128 </simpara>\r
129 <simpara><emphasis role="strong">NOTE</emphasis>: see the NOTE for the <emphasis>--shared</emphasis> option.</simpara>\r
130 </listitem>\r
131 </varlistentry>\r
132 <varlistentry>\r
133 <term>\r
134 --quiet\r
135 </term>\r
136 <term>\r
137 -q\r
138 </term>\r
139 <listitem>\r
140 <simpara>\r
141         Operate quietly.  Progress is not reported to the standard\r
142         error stream. This flag is also passed to the rsync\r
143         command when given.\r
144 </simpara>\r
145 </listitem>\r
146 </varlistentry>\r
147 <varlistentry>\r
148 <term>\r
149 --verbose\r
150 </term>\r
151 <term>\r
152 -v\r
153 </term>\r
154 <listitem>\r
155 <simpara>\r
156         Run verbosely. Does not affect the reporting of progress status\r
157         to the standard error stream.\r
158 </simpara>\r
159 </listitem>\r
160 </varlistentry>\r
161 <varlistentry>\r
162 <term>\r
163 --progress\r
164 </term>\r
165 <listitem>\r
166 <simpara>\r
167         Progress status is reported on the standard error stream\r
168         by default when it is attached to a terminal, unless -q\r
169         is specified. This flag forces progress status even if the\r
170         standard error stream is not directed to a terminal.\r
171 </simpara>\r
172 </listitem>\r
173 </varlistentry>\r
174 <varlistentry>\r
175 <term>\r
176 --no-checkout\r
177 </term>\r
178 <term>\r
179 -n\r
180 </term>\r
181 <listitem>\r
182 <simpara>\r
183         No checkout of HEAD is performed after the clone is complete.\r
184 </simpara>\r
185 </listitem>\r
186 </varlistentry>\r
187 <varlistentry>\r
188 <term>\r
189 --bare\r
190 </term>\r
191 <listitem>\r
192 <simpara>\r
193         Make a <emphasis>bare</emphasis> GIT repository.  That is, instead of\r
194         creating <emphasis>&lt;directory&gt;</emphasis> and placing the administrative\r
195         files in <emphasis>&lt;directory&gt;/.git</emphasis>, make the <emphasis>&lt;directory&gt;</emphasis>\r
196         itself the <emphasis>$GIT_DIR</emphasis>. This obviously implies the <emphasis>-n</emphasis>\r
197         because there is nowhere to check out the working tree.\r
198         Also the branch heads at the remote are copied directly\r
199         to corresponding local branch heads, without mapping\r
200         them to <emphasis>refs/remotes/origin/</emphasis>.  When this option is\r
201         used, neither remote-tracking branches nor the related\r
202         configuration variables are created.\r
203 </simpara>\r
204 </listitem>\r
205 </varlistentry>\r
206 <varlistentry>\r
207 <term>\r
208 --mirror\r
209 </term>\r
210 <listitem>\r
211 <simpara>\r
212         Set up a mirror of the source repository.  This implies <emphasis>--bare</emphasis>.\r
213         Compared to <emphasis>--bare</emphasis>, <emphasis>--mirror</emphasis> not only maps local branches of the\r
214         source to local branches of the target, it maps all refs (including\r
215         remote-tracking branches, notes etc.) and sets up a refspec configuration such\r
216         that all these refs are overwritten by a <emphasis>git remote update</emphasis> in the\r
217         target repository.\r
218 </simpara>\r
219 </listitem>\r
220 </varlistentry>\r
221 <varlistentry>\r
222 <term>\r
223 --origin &lt;name&gt;\r
224 </term>\r
225 <term>\r
226 -o &lt;name&gt;\r
227 </term>\r
228 <listitem>\r
229 <simpara>\r
230         Instead of using the remote name <emphasis>origin</emphasis> to keep track\r
231         of the upstream repository, use <emphasis>&lt;name&gt;</emphasis>.\r
232 </simpara>\r
233 </listitem>\r
234 </varlistentry>\r
235 <varlistentry>\r
236 <term>\r
237 --branch &lt;name&gt;\r
238 </term>\r
239 <term>\r
240 -b &lt;name&gt;\r
241 </term>\r
242 <listitem>\r
243 <simpara>\r
244         Instead of pointing the newly created HEAD to the branch pointed\r
245         to by the cloned repository's HEAD, point to <emphasis>&lt;name&gt;</emphasis> branch\r
246         instead. <emphasis>--branch</emphasis> can also take tags and treat them like\r
247         detached HEAD. In a non-bare repository, this is the branch\r
248         that will be checked out.\r
249 </simpara>\r
250 </listitem>\r
251 </varlistentry>\r
252 <varlistentry>\r
253 <term>\r
254 --upload-pack &lt;upload-pack&gt;\r
255 </term>\r
256 <term>\r
257 -u &lt;upload-pack&gt;\r
258 </term>\r
259 <listitem>\r
260 <simpara>\r
261         When given, and the repository to clone from is accessed\r
262         via ssh, this specifies a non-default path for the command\r
263         run on the other end.\r
264 </simpara>\r
265 </listitem>\r
266 </varlistentry>\r
267 <varlistentry>\r
268 <term>\r
269 --template=&lt;template_directory&gt;\r
270 </term>\r
271 <listitem>\r
272 <simpara>\r
273         Specify the directory from which templates will be used;\r
274         (See the "TEMPLATE DIRECTORY" section of <xref linkend="git-init(1)" />.)\r
275 </simpara>\r
276 </listitem>\r
277 </varlistentry>\r
278 <varlistentry>\r
279 <term>\r
280 --config &lt;key&gt;=&lt;value&gt;\r
281 </term>\r
282 <term>\r
283 -c &lt;key&gt;=&lt;value&gt;\r
284 </term>\r
285 <listitem>\r
286 <simpara>\r
287         Set a configuration variable in the newly-created repository;\r
288         this takes effect immediately after the repository is\r
289         initialized, but before the remote history is fetched or any\r
290         files checked out.  The key is in the same format as expected by\r
291         <xref linkend="git-config(1)" /> (e.g., <emphasis>core.eol=true</emphasis>). If multiple\r
292         values are given for the same key, each value will be written to\r
293         the config file. This makes it safe, for example, to add\r
294         additional fetch refspecs to the origin remote.\r
295 </simpara>\r
296 </listitem>\r
297 </varlistentry>\r
298 <varlistentry>\r
299 <term>\r
300 --depth &lt;depth&gt;\r
301 </term>\r
302 <listitem>\r
303 <simpara>\r
304         Create a <emphasis>shallow</emphasis> clone with a history truncated to the\r
305         specified number of revisions.  A shallow repository has a\r
306         number of limitations (you cannot clone or fetch from\r
307         it, nor push from nor into it), but is adequate if you\r
308         are only interested in the recent history of a large project\r
309         with a long history, and would want to send in fixes\r
310         as patches.\r
311 </simpara>\r
312 </listitem>\r
313 </varlistentry>\r
314 <varlistentry>\r
315 <term>\r
316 --single-branch\r
317 </term>\r
318 <listitem>\r
319 <simpara>\r
320         Clone only the history leading to the tip of a single branch,\r
321         either specified by the <emphasis>--branch</emphasis> option or the primary\r
322         branch remote's <emphasis>HEAD</emphasis> points at. When creating a shallow\r
323         clone with the <emphasis>--depth</emphasis> option, this is the default, unless\r
324         <emphasis>--no-single-branch</emphasis> is given to fetch the histories near the\r
325         tips of all branches.\r
326 </simpara>\r
327 </listitem>\r
328 </varlistentry>\r
329 <varlistentry>\r
330 <term>\r
331 --recursive\r
332 </term>\r
333 <term>\r
334 --recurse-submodules\r
335 </term>\r
336 <listitem>\r
337 <simpara>\r
338         After the clone is created, initialize all submodules within,\r
339         using their default settings. This is equivalent to running\r
340         <emphasis>git submodule update --init --recursive</emphasis> immediately after\r
341         the clone is finished. This option is ignored if the cloned\r
342         repository does not have a worktree/checkout (i.e. if any of\r
343         <emphasis>--no-checkout</emphasis>/<emphasis>-n</emphasis>, <emphasis>--bare</emphasis>, or <emphasis>--mirror</emphasis> is given)\r
344 </simpara>\r
345 </listitem>\r
346 </varlistentry>\r
347 <varlistentry>\r
348 <term>\r
349 --separate-git-dir=&lt;git dir&gt;\r
350 </term>\r
351 <listitem>\r
352 <simpara>\r
353         Instead of placing the cloned repository where it is supposed\r
354         to be, place the cloned repository at the specified directory,\r
355         then make a filesytem-agnostic git symbolic link to there.\r
356         The result is git repository can be separated from working\r
357         tree.\r
358 </simpara>\r
359 </listitem>\r
360 </varlistentry>\r
361 <varlistentry>\r
362 <term>\r
363 &lt;repository&gt;\r
364 </term>\r
365 <listitem>\r
366 <simpara>\r
367         The (possibly remote) repository to clone from.  See the\r
368         <link linkend="URLS">URLS</link> section below for more information on specifying\r
369         repositories.\r
370 </simpara>\r
371 </listitem>\r
372 </varlistentry>\r
373 <varlistentry>\r
374 <term>\r
375 &lt;directory&gt;\r
376 </term>\r
377 <listitem>\r
378 <simpara>\r
379         The name of a new directory to clone into.  The "humanish"\r
380         part of the source repository is used if no directory is\r
381         explicitly given (<emphasis>repo</emphasis> for <emphasis>/path/to/repo.git</emphasis> and <emphasis>foo</emphasis>\r
382         for <emphasis>host.xz:foo/.git</emphasis>).  Cloning into an existing directory\r
383         is only allowed if the directory is empty.\r
384 </simpara>\r
385 </listitem>\r
386 </varlistentry>\r
387 </variablelist>\r
388 </simplesect>\r
389 <simplesect id="_git_urls_anchor_id_urls_xreflabel_urls">\r
390 <title>GIT URLS<anchor id="URLS" xreflabel="[URLS]"/></title>\r
391 <simpara>In general, URLs contain information about the transport protocol, the\r
392 address of the remote server, and the path to the repository.\r
393 Depending on the transport protocol, some of this information may be\r
394 absent.</simpara>\r
395 <simpara>Git natively supports ssh, git, http, https, ftp, ftps, and rsync\r
396 protocols. The following syntaxes may be used with them:</simpara>\r
397 <itemizedlist>\r
398 <listitem>\r
399 <simpara>\r
400 ssh://&#91;user@&#93;host.xz&#91;:port&#93;/path/to/repo.git/\r
401 </simpara>\r
402 </listitem>\r
403 <listitem>\r
404 <simpara>\r
405 git://host.xz&#91;:port&#93;/path/to/repo.git/\r
406 </simpara>\r
407 </listitem>\r
408 <listitem>\r
409 <simpara>\r
410 http&#91;s&#93;://host.xz&#91;:port&#93;/path/to/repo.git/\r
411 </simpara>\r
412 </listitem>\r
413 <listitem>\r
414 <simpara>\r
415 ftp&#91;s&#93;://host.xz&#91;:port&#93;/path/to/repo.git/\r
416 </simpara>\r
417 </listitem>\r
418 <listitem>\r
419 <simpara>\r
420 rsync://host.xz/path/to/repo.git/\r
421 </simpara>\r
422 </listitem>\r
423 </itemizedlist>\r
424 <simpara>An alternative scp-like syntax may also be used with the ssh protocol:</simpara>\r
425 <itemizedlist>\r
426 <listitem>\r
427 <simpara>\r
428 &#91;user@&#93;host.xz:path/to/repo.git/\r
429 </simpara>\r
430 </listitem>\r
431 </itemizedlist>\r
432 <simpara>The ssh and git protocols additionally support ~username expansion:</simpara>\r
433 <itemizedlist>\r
434 <listitem>\r
435 <simpara>\r
436 ssh://&#91;user@&#93;host.xz&#91;:port&#93;/~&#91;user&#93;/path/to/repo.git/\r
437 </simpara>\r
438 </listitem>\r
439 <listitem>\r
440 <simpara>\r
441 git://host.xz&#91;:port&#93;/~&#91;user&#93;/path/to/repo.git/\r
442 </simpara>\r
443 </listitem>\r
444 <listitem>\r
445 <simpara>\r
446 &#91;user@&#93;host.xz:/~&#91;user&#93;/path/to/repo.git/\r
447 </simpara>\r
448 </listitem>\r
449 </itemizedlist>\r
450 <simpara>For local repositories, also supported by git natively, the following\r
451 syntaxes may be used:</simpara>\r
452 <itemizedlist>\r
453 <listitem>\r
454 <simpara>\r
455 /path/to/repo.git/\r
456 </simpara>\r
457 </listitem>\r
458 <listitem>\r
459 <simpara>\r
460 <ulink url="file:///path/to/repo.git/">file:///path/to/repo.git/</ulink>\r
461 </simpara>\r
462 </listitem>\r
463 </itemizedlist>\r
464 <simpara>These two syntaxes are mostly equivalent, except the former implies\r
465 --local option.</simpara>\r
466 <simpara>When git doesn't know how to handle a certain transport protocol, it\r
467 attempts to use the <emphasis>remote-&lt;transport&gt;</emphasis> remote helper, if one\r
468 exists. To explicitly request a remote helper, the following syntax\r
469 may be used:</simpara>\r
470 <itemizedlist>\r
471 <listitem>\r
472 <simpara>\r
473 &lt;transport&gt;::&lt;address&gt;\r
474 </simpara>\r
475 </listitem>\r
476 </itemizedlist>\r
477 <simpara>where &lt;address&gt; may be a path, a server and path, or an arbitrary\r
478 URL-like string recognized by the specific remote helper being\r
479 invoked. See <xref linkend="git-remote-helpers(1)" /> for details.</simpara>\r
480 <simpara>If there are a large number of similarly-named remote repositories and\r
481 you want to use a different format for them (such that the URLs you\r
482 use will be rewritten into URLs that work), you can create a\r
483 configuration section of the form:</simpara>\r
484 <screen>        [url "&lt;actual url base&gt;"]\r
485                 insteadOf = &lt;other url base&gt;</screen>\r
486 <simpara>For example, with this:</simpara>\r
487 <screen>        [url "git://git.host.xz/"]\r
488                 insteadOf = host.xz:/path/to/\r
489                 insteadOf = work:</screen>\r
490 <simpara>a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be\r
491 rewritten in any context that takes a URL to be "git://git.host.xz/repo.git".</simpara>\r
492 <simpara>If you want to rewrite URLs for push only, you can create a\r
493 configuration section of the form:</simpara>\r
494 <screen>        [url "&lt;actual url base&gt;"]\r
495                 pushInsteadOf = &lt;other url base&gt;</screen>\r
496 <simpara>For example, with this:</simpara>\r
497 <screen>        [url "ssh://example.org/"]\r
498                 pushInsteadOf = git://example.org/</screen>\r
499 <simpara>a URL like "git://example.org/path/to/repo.git" will be rewritten to\r
500 "ssh://example.org/path/to/repo.git" for pushes, but pulls will still\r
501 use the original URL.</simpara>\r
502 </simplesect>\r
503 <simplesect id="_examples">\r
504 <title>Examples</title>\r
505 <itemizedlist>\r
506 <listitem>\r
507 <simpara>\r
508 Clone from upstream:\r
509 </simpara>\r
510 <screen>$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6\r
511 $ cd my2.6\r
512 $ make</screen>\r
513 </listitem>\r
514 <listitem>\r
515 <simpara>\r
516 Make a local clone that borrows from the current directory, without checking things out:\r
517 </simpara>\r
518 <screen>$ git clone -l -s -n . ../copy\r
519 $ cd ../copy\r
520 $ git show-branch</screen>\r
521 </listitem>\r
522 <listitem>\r
523 <simpara>\r
524 Clone from upstream while borrowing from an existing local directory:\r
525 </simpara>\r
526 <screen>$ git clone --reference my2.6 \\r
527         git://git.kernel.org/pub/scm/.../linux-2.7 \\r
528         my2.7\r
529 $ cd my2.7</screen>\r
530 </listitem>\r
531 <listitem>\r
532 <simpara>\r
533 Create a bare repository to publish your changes to the public:\r
534 </simpara>\r
535 <screen>$ git clone --bare -l /home/proj/.git /pub/scm/proj.git</screen>\r
536 </listitem>\r
537 <listitem>\r
538 <simpara>\r
539 Create a repository on the kernel.org machine that borrows from Linus:\r
540 </simpara>\r
541 <screen>$ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \\r
542     /pub/scm/.../me/subsys-2.6.git</screen>\r
543 </listitem>\r
544 </itemizedlist>\r
545 </simplesect>\r
546 <simplesect id="_git">\r
547 <title>GIT</title>\r
548 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
549 </simplesect>\r
550 </article>\r