]>
Commit | Line | Data |
---|---|---|
215a7ad1 JH |
1 | git-clone(1) |
2 | ============ | |
6ec311da JH |
3 | |
4 | NAME | |
5 | ---- | |
29cf5e12 | 6 | git-clone - Clone a repository into a new directory |
6ec311da JH |
7 | |
8 | ||
9 | SYNOPSIS | |
10 | -------- | |
353ce815 | 11 | [verse] |
b1889c36 | 12 | 'git clone' [--template=<template_directory>] |
3d5c418f | 13 | [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] |
a57c8bac | 14 | [-o <name>] [-u <upload-pack>] [--reference <repository>] |
19391c37 | 15 | [--depth <depth>] [--] <repository> [<directory>] |
6ec311da JH |
16 | |
17 | DESCRIPTION | |
18 | ----------- | |
4607166d | 19 | |
db9819a4 BF |
20 | Clones a repository into a newly created directory, creates |
21 | remote-tracking branches for each branch in the cloned repository | |
1170e802 SG |
22 | (visible using `git branch -r`), and creates and checks out an initial |
23 | branch equal to the cloned repository's currently active branch. | |
4607166d | 24 | |
db9819a4 BF |
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 | |
1170e802 | 28 | current master branch, if any. |
4607166d | 29 | |
db9819a4 BF |
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. | |
6ec311da | 34 | |
f4bf2184 | 35 | |
6ec311da JH |
36 | OPTIONS |
37 | ------- | |
a2775c2a | 38 | --local:: |
6ec311da JH |
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. | |
3d5c418f JH |
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. | |
6ec311da | 57 | |
a2775c2a EB |
58 | --shared:: |
59 | -s:: | |
60 | When the repository to clone is on the local machine, | |
4607166d | 61 | instead of using hard links, automatically setup |
23edecbc | 62 | .git/objects/info/alternates to share the objects |
4607166d JH |
63 | with the source repository. The resulting repository |
64 | starts out without any object of its own. | |
84668872 MV |
65 | + |
66 | *NOTE*: this is a possibly dangerous operation; do *not* use | |
67 | it unless you understand what it does. If you clone your | |
2498a1ad BC |
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). | |
ba020ef5 | 71 | These objects may be removed by normal git operations (such as 'git-commit') |
483bc4f0 JN |
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. | |
28678b4f MV |
75 | |
76 | ||
a2775c2a | 77 | |
23edecbc SP |
78 | --reference <repository>:: |
79 | If the reference repository is on the local machine | |
80 | automatically setup .git/objects/info/alternates to | |
81 | obtain objects from the reference repository. Using | |
82 | an already existing repository as an alternate will | |
451e5931 | 83 | require fewer objects to be copied from the repository |
23edecbc | 84 | being cloned, reducing network and local storage costs. |
2498a1ad BC |
85 | + |
86 | *NOTE*: see NOTE to --shared option. | |
23edecbc | 87 | |
a2775c2a | 88 | --quiet:: |
6ec311da | 89 | -q:: |
d3296e37 SH |
90 | Operate quietly. This flag is also passed to the `rsync' |
91 | command when given. | |
6ec311da | 92 | |
fd0368f9 | 93 | --no-checkout:: |
a2775c2a EB |
94 | -n:: |
95 | No checkout of HEAD is performed after the clone is complete. | |
96 | ||
87e80c4b JH |
97 | --bare:: |
98 | Make a 'bare' GIT repository. That is, instead of | |
8a1a120c JH |
99 | creating `<directory>` and placing the administrative |
100 | files in `<directory>/.git`, make the `<directory>` | |
71821351 PB |
101 | itself the `$GIT_DIR`. This obviously implies the `-n` |
102 | because there is nowhere to check out the working tree. | |
103 | Also the branch heads at the remote are copied directly | |
104 | to corresponding local branch heads, without mapping | |
105 | them to `refs/remotes/origin/`. When this option is | |
36566cc0 BF |
106 | used, neither remote-tracking branches nor the related |
107 | configuration variables are created. | |
8a1a120c | 108 | |
ba158a32 | 109 | --origin <name>:: |
e6c310fd | 110 | -o <name>:: |
36566cc0 BF |
111 | Instead of using the remote name 'origin' to keep track |
112 | of the upstream repository, use <name> instead. | |
e6c310fd | 113 | |
a2775c2a | 114 | --upload-pack <upload-pack>:: |
6ec311da | 115 | -u <upload-pack>:: |
d3296e37 SH |
116 | When given, and the repository to clone from is accessed |
117 | via ssh, this specifies a non-default path for the command | |
6ec311da JH |
118 | run on the other end. |
119 | ||
a57c8bac JH |
120 | --template=<template_directory>:: |
121 | Specify the directory from which templates will be used; | |
122 | if unset the templates are taken from the installation | |
123 | defined default, typically `/usr/share/git-core/templates`. | |
124 | ||
f496454e | 125 | --depth <depth>:: |
f4bf2184 | 126 | Create a 'shallow' clone with a history truncated to the |
d9d10bb8 | 127 | specified number of revisions. A shallow repository has a |
f4bf2184 JH |
128 | number of limitations (you cannot clone or fetch from |
129 | it, nor push from nor into it), but is adequate if you | |
d9d10bb8 RW |
130 | are only interested in the recent history of a large project |
131 | with a long history, and would want to send in fixes | |
f4bf2184 JH |
132 | as patches. |
133 | ||
6ec311da | 134 | <repository>:: |
37ba0561 AR |
135 | The (possibly remote) repository to clone from. See the |
136 | <<URLS,URLS>> section below for more information on specifying | |
137 | repositories. | |
6ec311da JH |
138 | |
139 | <directory>:: | |
fb6a9f93 | 140 | The name of a new directory to clone into. The "humanish" |
0879aa28 AE |
141 | part of the source repository is used if no directory is |
142 | explicitly given ("repo" for "/path/to/repo.git" and "foo" | |
143 | for "host.xz:foo/.git"). Cloning into an existing directory | |
144 | is not allowed. | |
4607166d | 145 | |
347989f4 | 146 | :git-clone: 1 |
37ba0561 AR |
147 | include::urls.txt[] |
148 | ||
1e2ccd3a | 149 | Examples |
2b5f3ed3 | 150 | -------- |
1e2ccd3a JH |
151 | |
152 | Clone from upstream:: | |
153 | + | |
154 | ------------ | |
155 | $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6 | |
156 | $ cd my2.6 | |
157 | $ make | |
158 | ------------ | |
159 | ||
160 | ||
161 | Make a local clone that borrows from the current directory, without checking things out:: | |
162 | + | |
163 | ------------ | |
164 | $ git clone -l -s -n . ../copy | |
a6e3768f | 165 | $ cd ../copy |
1e2ccd3a JH |
166 | $ git show-branch |
167 | ------------ | |
168 | ||
8a1a120c | 169 | |
23edecbc SP |
170 | Clone from upstream while borrowing from an existing local directory:: |
171 | + | |
172 | ------------ | |
173 | $ git clone --reference my2.6 \ | |
174 | git://git.kernel.org/pub/scm/.../linux-2.7 \ | |
175 | my2.7 | |
176 | $ cd my2.7 | |
177 | ------------ | |
178 | ||
179 | ||
87e80c4b | 180 | Create a bare repository to publish your changes to the public:: |
8a1a120c JH |
181 | + |
182 | ------------ | |
87e80c4b | 183 | $ git clone --bare -l /home/proj/.git /pub/scm/proj.git |
8a1a120c JH |
184 | ------------ |
185 | ||
186 | ||
187 | Create a repository on the kernel.org machine that borrows from Linus:: | |
188 | + | |
189 | ------------ | |
87e80c4b | 190 | $ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \ |
8a1a120c JH |
191 | /pub/scm/.../me/subsys-2.6.git |
192 | ------------ | |
193 | ||
194 | ||
6ec311da JH |
195 | Author |
196 | ------ | |
197 | Written by Linus Torvalds <torvalds@osdl.org> | |
198 | ||
1e2ccd3a | 199 | |
6ec311da JH |
200 | Documentation |
201 | -------------- | |
0879aa28 | 202 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. |
6ec311da JH |
203 | |
204 | ||
205 | GIT | |
206 | --- | |
9e1f0a85 | 207 | Part of the linkgit:git[1] suite |