1GIT-CLONE(1) Git Manual GIT-CLONE(1)
2
3
4
6 git-clone - Clone a repository into a new directory
7
9 git clone [--template=<template_directory>]
10 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
11 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
12 [--separate-git-dir <git dir>]
13 [--depth <depth>] [--[no-]single-branch]
14 [--recursive | --recurse-submodules] [--] <repository>
15 [<directory>]
16
17
19 Clones a repository into a newly created directory, creates
20 remote-tracking branches for each branch in the cloned repository
21 (visible using git branch -r), and creates and checks out an initial
22 branch that is forked from the cloned repository’s currently active
23 branch.
24
25 After the clone, a plain git fetch without arguments will update all
26 the remote-tracking branches, and a git pull without arguments will in
27 addition merge the remote master branch into the current master branch,
28 if any (this is untrue when "--single-branch" is given; see below).
29
30 This default configuration is achieved by creating references to the
31 remote branch heads under refs/remotes/origin and by initializing
32 remote.origin.url and remote.origin.fetch configuration variables.
33
35 --local, -l
36 When the repository to clone from is on a local machine, this flag
37 bypasses the normal "Git aware" transport mechanism and clones the
38 repository by making a copy of HEAD and everything under objects
39 and refs directories. The files under .git/objects/ directory are
40 hardlinked to save space when possible.
41
42 If the repository is specified as a local path (e.g.,
43 /path/to/repo), this is the default, and --local is essentially a
44 no-op. If the repository is specified as a URL, then this flag is
45 ignored (and we never use the local optimizations). Specifying
46 --no-local will override the default when /path/to/repo is given,
47 using the regular Git transport instead.
48
49 To force copying instead of hardlinking (which may be desirable if
50 you are trying to make a back-up of your repository), but still
51 avoid the usual "Git aware" transport mechanism, --no-hardlinks can
52 be used.
53
54 --no-hardlinks
55 Optimize the cloning process from a repository on a local
56 filesystem by copying files under .git/objects directory.
57
58 --shared, -s
59 When the repository to clone is on the local machine, instead of
60 using hard links, automatically setup .git/objects/info/alternates
61 to share the objects with the source repository. The resulting
62 repository starts out without any object of its own.
63
64 NOTE: this is a possibly dangerous operation; do not use it unless
65 you understand what it does. If you clone your repository using
66 this option and then delete branches (or use any other Git command
67 that makes any existing commit unreferenced) in the source
68 repository, some objects may become unreferenced (or dangling).
69 These objects may be removed by normal Git operations (such as git
70 commit) which automatically call git gc --auto. (See git-gc(1).) If
71 these objects are removed and were referenced by the cloned
72 repository, then the cloned repository will become corrupt.
73
74 Note that running git repack without the -l option in a repository
75 cloned with -s will copy objects from the source repository into a
76 pack in the cloned repository, removing the disk space savings of
77 clone -s. It is safe, however, to run git gc, which uses the -l
78 option by default.
79
80 If you want to break the dependency of a repository cloned with -s
81 on its source repository, you can simply run git repack -a to copy
82 all objects from the source repository into a pack in the cloned
83 repository.
84
85 --reference <repository>
86 If the reference repository is on the local machine, automatically
87 setup .git/objects/info/alternates to obtain objects from the
88 reference repository. Using an already existing repository as an
89 alternate will require fewer objects to be copied from the
90 repository being cloned, reducing network and local storage costs.
91
92 NOTE: see the NOTE for the --shared option.
93
94 --quiet, -q
95 Operate quietly. Progress is not reported to the standard error
96 stream. This flag is also passed to the ‘rsync’ command when given.
97
98 --verbose, -v
99 Run verbosely. Does not affect the reporting of progress status to
100 the standard error stream.
101
102 --progress
103 Progress status is reported on the standard error stream by default
104 when it is attached to a terminal, unless -q is specified. This
105 flag forces progress status even if the standard error stream is
106 not directed to a terminal.
107
108 --no-checkout, -n
109 No checkout of HEAD is performed after the clone is complete.
110
111 --bare
112 Make a bare Git repository. That is, instead of creating
113 <directory> and placing the administrative files in
114 <directory>/.git, make the <directory> itself the $GIT_DIR. This
115 obviously implies the -n because there is nowhere to check out the
116 working tree. Also the branch heads at the remote are copied
117 directly to corresponding local branch heads, without mapping them
118 to refs/remotes/origin/. When this option is used, neither
119 remote-tracking branches nor the related configuration variables
120 are created.
121
122 --mirror
123 Set up a mirror of the source repository. This implies --bare.
124 Compared to --bare, --mirror not only maps local branches of the
125 source to local branches of the target, it maps all refs (including
126 remote-tracking branches, notes etc.) and sets up a refspec
127 configuration such that all these refs are overwritten by a git
128 remote update in the target repository.
129
130 --origin <name>, -o <name>
131 Instead of using the remote name origin to keep track of the
132 upstream repository, use <name>.
133
134 --branch <name>, -b <name>
135 Instead of pointing the newly created HEAD to the branch pointed to
136 by the cloned repository’s HEAD, point to <name> branch instead. In
137 a non-bare repository, this is the branch that will be checked out.
138 --branch can also take tags and detaches the HEAD at that commit in
139 the resulting repository.
140
141 --upload-pack <upload-pack>, -u <upload-pack>
142 When given, and the repository to clone from is accessed via ssh,
143 this specifies a non-default path for the command run on the other
144 end.
145
146 --template=<template_directory>
147 Specify the directory from which templates will be used; (See the
148 "TEMPLATE DIRECTORY" section of git-init(1).)
149
150 --config <key>=<value>, -c <key>=<value>
151 Set a configuration variable in the newly-created repository; this
152 takes effect immediately after the repository is initialized, but
153 before the remote history is fetched or any files checked out. The
154 key is in the same format as expected by git-config(1) (e.g.,
155 core.eol=true). If multiple values are given for the same key, each
156 value will be written to the config file. This makes it safe, for
157 example, to add additional fetch refspecs to the origin remote.
158
159 --depth <depth>
160 Create a shallow clone with a history truncated to the specified
161 number of revisions. A shallow repository has a number of
162 limitations (you cannot clone or fetch from it, nor push from nor
163 into it), but is adequate if you are only interested in the recent
164 history of a large project with a long history, and would want to
165 send in fixes as patches.
166
167 --[no-]single-branch
168 Clone only the history leading to the tip of a single branch,
169 either specified by the --branch option or the primary branch
170 remote’s HEAD points at. When creating a shallow clone with the
171 --depth option, this is the default, unless --no-single-branch is
172 given to fetch the histories near the tips of all branches. Further
173 fetches into the resulting repository will only update the
174 remote-tracking branch for the branch this option was used for the
175 initial cloning. If the HEAD at the remote did not point at any
176 branch when --single-branch clone was made, no remote-tracking
177 branch is created.
178
179 --recursive, --recurse-submodules
180 After the clone is created, initialize all submodules within, using
181 their default settings. This is equivalent to running git submodule
182 update --init --recursive immediately after the clone is finished.
183 This option is ignored if the cloned repository does not have a
184 worktree/checkout (i.e. if any of --no-checkout/-n, --bare, or
185 --mirror is given)
186
187 --separate-git-dir=<git dir>
188 Instead of placing the cloned repository where it is supposed to
189 be, place the cloned repository at the specified directory, then
190 make a filesytem-agnostic Git symbolic link to there. The result is
191 Git repository can be separated from working tree.
192
193 <repository>
194 The (possibly remote) repository to clone from. See the URLS
195 section below for more information on specifying repositories.
196
197 <directory>
198 The name of a new directory to clone into. The "humanish" part of
199 the source repository is used if no directory is explicitly given
200 (repo for /path/to/repo.git and foo for host.xz:foo/.git). Cloning
201 into an existing directory is only allowed if the directory is
202 empty.
203
205 In general, URLs contain information about the transport protocol, the
206 address of the remote server, and the path to the repository. Depending
207 on the transport protocol, some of this information may be absent.
208
209 Git supports ssh, git, http, and https protocols (in addition, ftp, and
210 ftps can be used for fetching and rsync can be used for fetching and
211 pushing, but these are inefficient and deprecated; do not use them).
212
213 The following syntaxes may be used with them:
214
215 · ssh://[user@]host.xz[:port]/path/to/repo.git/
216
217 · git://host.xz[:port]/path/to/repo.git/
218
219 · http[s]://host.xz[:port]/path/to/repo.git/
220
221 · ftp[s]://host.xz[:port]/path/to/repo.git/
222
223 · rsync://host.xz/path/to/repo.git/
224
225 An alternative scp-like syntax may also be used with the ssh protocol:
226
227 · [user@]host.xz:path/to/repo.git/
228
229 The ssh and git protocols additionally support ~username expansion:
230
231 · ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
232
233 · git://host.xz[:port]/~[user]/path/to/repo.git/
234
235 · [user@]host.xz:/~[user]/path/to/repo.git/
236
237 For local repositories, also supported by Git natively, the following
238 syntaxes may be used:
239
240 · /path/to/repo.git/
241
242 · file:///path/to/repo.git/
243
244 These two syntaxes are mostly equivalent, except the former implies
245 --local option.
246
247 When Git doesn’t know how to handle a certain transport protocol, it
248 attempts to use the remote-<transport> remote helper, if one exists. To
249 explicitly request a remote helper, the following syntax may be used:
250
251 · <transport>::<address>
252
253 where <address> may be a path, a server and path, or an arbitrary
254 URL-like string recognized by the specific remote helper being invoked.
255 See gitremote-helpers(1) for details.
256
257 If there are a large number of similarly-named remote repositories and
258 you want to use a different format for them (such that the URLs you use
259 will be rewritten into URLs that work), you can create a configuration
260 section of the form:
261
262 [url "<actual url base>"]
263 insteadOf = <other url base>
264
265
266 For example, with this:
267
268 [url "git://git.host.xz/"]
269 insteadOf = host.xz:/path/to/
270 insteadOf = work:
271
272
273 a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
274 rewritten in any context that takes a URL to be
275 "git://git.host.xz/repo.git".
276
277 If you want to rewrite URLs for push only, you can create a
278 configuration section of the form:
279
280 [url "<actual url base>"]
281 pushInsteadOf = <other url base>
282
283
284 For example, with this:
285
286 [url "ssh://example.org/"]
287 pushInsteadOf = git://example.org/
288
289
290 a URL like "git://example.org/path/to/repo.git" will be rewritten to
291 "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
292 use the original URL.
293
295 · Clone from upstream:
296
297 $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
298 $ cd my2.6
299 $ make
300
301
302 · Make a local clone that borrows from the current directory, without
303 checking things out:
304
305 $ git clone -l -s -n . ../copy
306 $ cd ../copy
307 $ git show-branch
308
309
310 · Clone from upstream while borrowing from an existing local
311 directory:
312
313 $ git clone --reference my2.6 \
314 git://git.kernel.org/pub/scm/.../linux-2.7 \
315 my2.7
316 $ cd my2.7
317
318
319 · Create a bare repository to publish your changes to the public:
320
321 $ git clone --bare -l /home/proj/.git /pub/scm/proj.git
322
323
324 · Create a repository on the kernel.org machine that borrows from
325 Linus:
326
327 $ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \
328 /pub/scm/.../me/subsys-2.6.git
329
330
332 Part of the git(1) suite
333
334
335
336Git 1.8.3.1 11/19/2018 GIT-CLONE(1)