]>
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] |
3d5c418f JH |
12 | 'git-clone' [--template=<template_directory>] |
13 | [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] | |
a57c8bac | 14 | [-o <name>] [-u <upload-pack>] [--reference <repository>] |
f496454e | 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. | |
a2775c2a | 65 | |
23edecbc SP |
66 | --reference <repository>:: |
67 | If the reference repository is on the local machine | |
68 | automatically setup .git/objects/info/alternates to | |
69 | obtain objects from the reference repository. Using | |
70 | an already existing repository as an alternate will | |
71 | require less objects to be copied from the repository | |
72 | being cloned, reducing network and local storage costs. | |
73 | ||
a2775c2a | 74 | --quiet:: |
6ec311da JH |
75 | -q:: |
76 | Operate quietly. This flag is passed to "rsync" and | |
efc7fa53 | 77 | "git-fetch-pack" commands when given. |
6ec311da | 78 | |
fd0368f9 | 79 | --no-checkout:: |
a2775c2a EB |
80 | -n:: |
81 | No checkout of HEAD is performed after the clone is complete. | |
82 | ||
87e80c4b JH |
83 | --bare:: |
84 | Make a 'bare' GIT repository. That is, instead of | |
8a1a120c JH |
85 | creating `<directory>` and placing the administrative |
86 | files in `<directory>/.git`, make the `<directory>` | |
71821351 PB |
87 | itself the `$GIT_DIR`. This obviously implies the `-n` |
88 | because there is nowhere to check out the working tree. | |
89 | Also the branch heads at the remote are copied directly | |
90 | to corresponding local branch heads, without mapping | |
91 | them to `refs/remotes/origin/`. When this option is | |
36566cc0 BF |
92 | used, neither remote-tracking branches nor the related |
93 | configuration variables are created. | |
8a1a120c | 94 | |
ba158a32 | 95 | --origin <name>:: |
e6c310fd | 96 | -o <name>:: |
36566cc0 BF |
97 | Instead of using the remote name 'origin' to keep track |
98 | of the upstream repository, use <name> instead. | |
e6c310fd | 99 | |
a2775c2a | 100 | --upload-pack <upload-pack>:: |
6ec311da JH |
101 | -u <upload-pack>:: |
102 | When given, and the repository to clone from is handled | |
efc7fa53 | 103 | by 'git-fetch-pack', '--exec=<upload-pack>' is passed to |
6ec311da JH |
104 | the command to specify non-default path for the command |
105 | run on the other end. | |
106 | ||
a57c8bac JH |
107 | --template=<template_directory>:: |
108 | Specify the directory from which templates will be used; | |
109 | if unset the templates are taken from the installation | |
110 | defined default, typically `/usr/share/git-core/templates`. | |
111 | ||
f496454e | 112 | --depth <depth>:: |
f4bf2184 JH |
113 | Create a 'shallow' clone with a history truncated to the |
114 | specified number of revs. A shallow repository has | |
115 | number of limitations (you cannot clone or fetch from | |
116 | it, nor push from nor into it), but is adequate if you | |
117 | want to only look at near the tip of a large project | |
118 | with a long history, and would want to send in a fixes | |
119 | as patches. | |
120 | ||
6ec311da | 121 | <repository>:: |
37ba0561 AR |
122 | The (possibly remote) repository to clone from. See the |
123 | <<URLS,URLS>> section below for more information on specifying | |
124 | repositories. | |
6ec311da JH |
125 | |
126 | <directory>:: | |
fb6a9f93 | 127 | The name of a new directory to clone into. The "humanish" |
0879aa28 AE |
128 | part of the source repository is used if no directory is |
129 | explicitly given ("repo" for "/path/to/repo.git" and "foo" | |
130 | for "host.xz:foo/.git"). Cloning into an existing directory | |
131 | is not allowed. | |
4607166d | 132 | |
37ba0561 AR |
133 | include::urls.txt[] |
134 | ||
1e2ccd3a | 135 | Examples |
2b5f3ed3 | 136 | -------- |
1e2ccd3a JH |
137 | |
138 | Clone from upstream:: | |
139 | + | |
140 | ------------ | |
141 | $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6 | |
142 | $ cd my2.6 | |
143 | $ make | |
144 | ------------ | |
145 | ||
146 | ||
147 | Make a local clone that borrows from the current directory, without checking things out:: | |
148 | + | |
149 | ------------ | |
150 | $ git clone -l -s -n . ../copy | |
a6e3768f | 151 | $ cd ../copy |
1e2ccd3a JH |
152 | $ git show-branch |
153 | ------------ | |
154 | ||
8a1a120c | 155 | |
23edecbc SP |
156 | Clone from upstream while borrowing from an existing local directory:: |
157 | + | |
158 | ------------ | |
159 | $ git clone --reference my2.6 \ | |
160 | git://git.kernel.org/pub/scm/.../linux-2.7 \ | |
161 | my2.7 | |
162 | $ cd my2.7 | |
163 | ------------ | |
164 | ||
165 | ||
87e80c4b | 166 | Create a bare repository to publish your changes to the public:: |
8a1a120c JH |
167 | + |
168 | ------------ | |
87e80c4b | 169 | $ git clone --bare -l /home/proj/.git /pub/scm/proj.git |
8a1a120c JH |
170 | ------------ |
171 | ||
172 | ||
173 | Create a repository on the kernel.org machine that borrows from Linus:: | |
174 | + | |
175 | ------------ | |
87e80c4b | 176 | $ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \ |
8a1a120c JH |
177 | /pub/scm/.../me/subsys-2.6.git |
178 | ------------ | |
179 | ||
180 | ||
6ec311da JH |
181 | Author |
182 | ------ | |
183 | Written by Linus Torvalds <torvalds@osdl.org> | |
184 | ||
1e2ccd3a | 185 | |
6ec311da JH |
186 | Documentation |
187 | -------------- | |
0879aa28 | 188 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. |
6ec311da JH |
189 | |
190 | ||
191 | GIT | |
192 | --- | |
a7154e91 | 193 | Part of the gitlink:git[7] suite |