]> git.ipfire.org Git - thirdparty/git.git/blob - Documentation/git-clone.txt
Merge branch 'pk/fast-import-tars'
[thirdparty/git.git] / Documentation / git-clone.txt
1 git-clone(1)
2 ============
3
4 NAME
5 ----
6 git-clone - Clone a repository into a new directory
7
8
9 SYNOPSIS
10 --------
11 [verse]
12 'git clone' [--template=<template_directory>]
13 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
14 [-o <name>] [-u <upload-pack>] [--reference <repository>]
15 [--depth <depth>] [--recursive] [--] <repository> [<directory>]
16
17 DESCRIPTION
18 -----------
19
20 Clones a repository into a newly created directory, creates
21 remote-tracking branches for each branch in the cloned repository
22 (visible using `git branch -r`), and creates and checks out an initial
23 branch equal to the cloned repository's currently active branch.
24
25 After the clone, a plain `git fetch` without arguments will update
26 all the remote-tracking branches, and a `git pull` without
27 arguments will in addition merge the remote master branch into the
28 current master branch, if any.
29
30 This default configuration is achieved by creating references to
31 the remote branch heads under `$GIT_DIR/refs/remotes/origin` and
32 by initializing `remote.origin.url` and `remote.origin.fetch`
33 configuration variables.
34
35
36 OPTIONS
37 -------
38 --local::
39 -l::
40 When the repository to clone from is on a local machine,
41 this flag bypasses normal "git aware" transport
42 mechanism and clones the repository by making a copy of
43 HEAD and everything under objects and refs directories.
44 The files under `.git/objects/` directory are hardlinked
45 to save space when possible. This is now the default when
46 the source repository is specified with `/path/to/repo`
47 syntax, so it essentially is a no-op option. To force
48 copying instead of hardlinking (which may be desirable
49 if you are trying to make a back-up of your repository),
50 but still avoid the usual "git aware" transport
51 mechanism, `--no-hardlinks` can be used.
52
53 --no-hardlinks::
54 Optimize the cloning process from a repository on a
55 local filesystem by copying files under `.git/objects`
56 directory.
57
58 --shared::
59 -s::
60 When the repository to clone is on the local machine,
61 instead of using hard links, automatically setup
62 .git/objects/info/alternates to share the objects
63 with the source repository. The resulting repository
64 starts out without any object of its own.
65 +
66 *NOTE*: this is a possibly dangerous operation; do *not* use
67 it unless you understand what it does. If you clone your
68 repository using this option and then delete branches (or use any
69 other git command that makes any existing commit unreferenced) in the
70 source repository, some objects may become unreferenced (or dangling).
71 These objects may be removed by normal git operations (such as 'git-commit')
72 which automatically call `git gc --auto`. (See linkgit:git-gc[1].)
73 If these objects are removed and were referenced by the cloned repository,
74 then the cloned repository will become corrupt.
75 +
76 Note that running `git repack` without the `-l` option in a repository
77 cloned with `-s` will copy objects from the source repository into a pack
78 in the cloned repository, removing the disk space savings of `clone -s`.
79 It is safe, however, to run `git gc`, which uses the `-l` option by
80 default.
81 +
82 If you want to break the dependency of a repository cloned with `-s` on
83 its source repository, you can simply run `git repack -a` to copy all
84 objects from the source repository into a pack in the cloned repository.
85
86 --reference <repository>::
87 If the reference repository is on the local machine,
88 automatically setup .git/objects/info/alternates to
89 obtain objects from the reference repository. Using
90 an already existing repository as an alternate will
91 require fewer objects to be copied from the repository
92 being cloned, reducing network and local storage costs.
93 +
94 *NOTE*: see NOTE to --shared option.
95
96 --quiet::
97 -q::
98 Operate quietly. This flag is also passed to the `rsync'
99 command when given.
100
101 --verbose::
102 -v::
103 Display the progressbar, even in case the standard output is not
104 a terminal.
105
106 --no-checkout::
107 -n::
108 No checkout of HEAD is performed after the clone is complete.
109
110 --bare::
111 Make a 'bare' GIT repository. That is, instead of
112 creating `<directory>` and placing the administrative
113 files in `<directory>/.git`, make the `<directory>`
114 itself the `$GIT_DIR`. This obviously implies the `-n`
115 because there is nowhere to check out the working tree.
116 Also the branch heads at the remote are copied directly
117 to corresponding local branch heads, without mapping
118 them to `refs/remotes/origin/`. When this option is
119 used, neither remote-tracking branches nor the related
120 configuration variables are created.
121
122 --mirror::
123 Set up a mirror of the remote repository. This implies --bare.
124
125 --origin <name>::
126 -o <name>::
127 Instead of using the remote name 'origin' to keep track
128 of the upstream repository, use <name>.
129
130 --branch <name>::
131 -b <name>::
132 Instead of pointing the newly created HEAD to the branch pointed
133 to by the cloned repositoroy's HEAD, point to <name> branch
134 instead. In a non-bare repository, this is the branch that will
135 be checked out.
136
137 --upload-pack <upload-pack>::
138 -u <upload-pack>::
139 When given, and the repository to clone from is accessed
140 via ssh, this specifies a non-default path for the command
141 run on the other end.
142
143 --template=<template_directory>::
144 Specify the directory from which templates will be used;
145 if unset the templates are taken from the installation
146 defined default, typically `/usr/share/git-core/templates`.
147
148 --depth <depth>::
149 Create a 'shallow' clone with a history truncated to the
150 specified number of revisions. A shallow repository has a
151 number of limitations (you cannot clone or fetch from
152 it, nor push from nor into it), but is adequate if you
153 are only interested in the recent history of a large project
154 with a long history, and would want to send in fixes
155 as patches.
156
157 --recursive::
158 After the clone is created, initialize all submodules within,
159 using their default settings. This is equivalent to running
160 'git submodule update --init --recursive' immediately after
161 the clone is finished. This option is ignored if the cloned
162 repository does not have a worktree/checkout (i.e. if any of
163 `--no-checkout`/`-n`, `--bare`, or `--mirror` is given)
164
165 <repository>::
166 The (possibly remote) repository to clone from. See the
167 <<URLS,URLS>> section below for more information on specifying
168 repositories.
169
170 <directory>::
171 The name of a new directory to clone into. The "humanish"
172 part of the source repository is used if no directory is
173 explicitly given ("repo" for "/path/to/repo.git" and "foo"
174 for "host.xz:foo/.git"). Cloning into an existing directory
175 is only allowed if the directory is empty.
176
177 :git-clone: 1
178 include::urls.txt[]
179
180 Examples
181 --------
182
183 Clone from upstream::
184 +
185 ------------
186 $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
187 $ cd my2.6
188 $ make
189 ------------
190
191
192 Make a local clone that borrows from the current directory, without checking things out::
193 +
194 ------------
195 $ git clone -l -s -n . ../copy
196 $ cd ../copy
197 $ git show-branch
198 ------------
199
200
201 Clone from upstream while borrowing from an existing local directory::
202 +
203 ------------
204 $ git clone --reference my2.6 \
205 git://git.kernel.org/pub/scm/.../linux-2.7 \
206 my2.7
207 $ cd my2.7
208 ------------
209
210
211 Create a bare repository to publish your changes to the public::
212 +
213 ------------
214 $ git clone --bare -l /home/proj/.git /pub/scm/proj.git
215 ------------
216
217
218 Create a repository on the kernel.org machine that borrows from Linus::
219 +
220 ------------
221 $ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \
222 /pub/scm/.../me/subsys-2.6.git
223 ------------
224
225
226 Author
227 ------
228 Written by Linus Torvalds <torvalds@osdl.org>
229
230
231 Documentation
232 --------------
233 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
234
235
236 GIT
237 ---
238 Part of the linkgit:git[1] suite