blob: 5bd64c7feec0e702d264055e6ee1f4c6b823efba [file] [log] [blame]
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -08001Gerrit2 - Uploading Changes
2===========================
3
4Gerrit supports three methods of uploading changes for review:
5
6* Use `repo upload`, to create changes for review
7* Use `git push`, to create changes for review
8* Use `git push`, and bypass code review
9
10All three methods use SSH public key authentication, which must
11first be configured by the uploading user.
12
13SSH Authentication
14------------------
15
Shawn O. Pearcee85964c2009-05-28 11:16:24 -070016Each user uploading changes to Gerrit must configure one
17or more SSH public keys. The per-user SSH key list can be
18accessed over the web within Gerrit by `Settings` (or by visting
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080019`http://'hostname'/settings`) then accessing the `SSH Keys` tab.
20
21To register a new SSH key for use with Gerrit, paste the contents
22of your `id_rsa.pub` or `id_dsa.pub` file into the text box and
23click the add button.
24
25[NOTE]
26Gerrit only understands SSH version 2 public keys. Keys may be
27supplied in either the OpenSSH format (key starts with `ssh-rsa`
28or `ssh-dss`) or the RFC 4716 format (file starts with `---- BEGIN
29SSH2 PUBLIC KEY ----`).
30
31Typically your SSH keys are stored in your home directory, under
32`~/.ssh`. If you don't have any keys yet, you can create a new
33one and protect it with a passphrase:
34
35====
36 ssh-keygen -t rsa
37====
38
39Then copy the content of the public key file onto your clipboard,
40and paste it into Gerrit's web interface:
41
42====
43 cat ~/.ssh/id_rsa.pub
44====
45
46[TIP]
47Users who frequently use Gerrit to upload changes will also want
48to consider starting a `ssh-agent`, and adding their key to the
49list managed by the agent, to reduce the frequency of entering the
50key's passphrase. Consult `man ssh-agent`, or your SSH client's
51documentation, for more details on configuration of the agent
52process and how to add the private key.
53
Shawn O. Pearce4016a932009-05-28 15:12:40 -070054Testing Your SSH Connection[[test_ssh]]
55---------------------------------------
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080056
57To verify your SSH key is working correctly, try using an SSH client
58to connect to Gerrit's SSHD port. By default Gerrit is running on
59port 29418, using the same hostname as the web server:
60
61====
62 $ ssh -p 29418 sshusername@hostname
63 gerrit: no shell available
64 Connection to hostname closed.
65====
66
67In the command above, `sshusername` is always the local part of your
68preferred email address (the text before the `@` sign). The exact
Shawn O. Pearcee85964c2009-05-28 11:16:24 -070069value chosen by Gerrit can be confirmed by visting `Settings`,
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080070and copying the `SSH Username` field. For example, a user who
71has selected a preferred email address of `john.doe@example.com`
Shawn O. Pearcee85964c2009-05-28 11:16:24 -070072would be assigned `john.doe` as their SSH username. For many users,
73this may also be identical to their local username.
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080074
75To determine the port number Gerrit is running on, visit the special
76information URL `http://'hostname'/ssh_info`, and copy the port
77number from the second field:
78
79====
80 $ curl http://hostname/ssh_info
81 hostname 29418
82====
83
84[TIP]
85If you are developing an automated tool to perform uploads to Gerrit,
86let the user supply the hostname or the web address for Gerrit,
87and obtain the port number on the fly from the `/ssh_info` URL.
88The returned output from this URL is always `'hostname' SP 'port'`,
89or `NOT_AVAILABLE` if the SSHD server isn't running.
90
91
92repo upload: Create Changes
93---------------------------
94
95To upload changes to a project using `repo`, ensure the manifest's
96review field has been configured to point to the Gerrit server.
97Only the hostname or the web address needs to be given in the
98manifest file. During upload `repo` will automatically determine the
99correct port number by reading `http://'reviewhostname'/ssh_info`
100when its invoked.
101
102Each new commit uploaded by `repo upload` will be converted into
103a change record on the server. Other users (e.g. project owners)
104who have configured Gerrit to notify them of new changes will be
105automatically sent an email message. Additional notifications can
106be sent through command line options.
107
108For more details on using `repo upload`, see `repo help upload`.
109
110
Shawn O. Pearce4016a932009-05-28 15:12:40 -0700111git push: Create Changes[[push_create]]
112---------------------------------------
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800113
114To create new changes for review, simply push into the project's
115magical `refs/for/'branch'` ref using any Git client tool:
116
117====
118 git push ssh://sshusername@hostname:29418/projectname HEAD:refs/for/branchname
119====
120
121E.g. `john.doe` can use git push to upload new changes for the
122`experimental` branch of project `kernel/common`, hosted at the
123`git.example.com` Gerrit server:
124
125====
126 git push ssh://john.doe@git.example.com:29418/kernel/common HEAD:refs/for/experimental
127====
128
129Each new commit uploaded by the `git push` client will be
130converted into a change record on the server. The remote ref
131`refs/for/experimental` is not actually created by Gerrit, even
132though the client's status messages may say otherwise.
133
134Other users (e.g. project owners) who have configured Gerrit to
135notify them of new changes will be automatically sent an email
136message when the push is completed.
137
138If you are frequently uploading changes to the same Gerrit server,
139consider adding an SSH host block in `~/.ssh/config` to remember
140your username, hostname and port number. This permits the use of
141shorter URLs on the command line, such as:
142
143====
144 $ cat ~/.ssh/config
145 ...
146 Host tr
147 Hostname git.example.com
148 Port 29418
149 User john.doe
150
151 $ git push tr:kernel/common HEAD:refs/for/experimental
152====
153
154Specific reviewers can be requested and/or additional ``carbon
155copies'' of the notification message may be sent by including these
Shawn O. Pearcefc0ec2f2009-05-28 11:20:06 -0700156as arguments to `git receive-pack`:
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800157
158====
Shawn O. Pearcefc0ec2f2009-05-28 11:20:06 -0700159 git push --receive-pack='git receive-pack --reviewer=a@a.com --cc=b@o.com' tr:kernel/common HEAD:refs/for/experimental
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800160====
161
162The `\--reviewer='email'` and `\--cc='email'` options may be
163specified as many times as necessary to cover all interested
164parties. Gerrit will automatically avoid sending duplicate email
165notifications, such as if one of the specified reviewers or CC
166addresses had also requested to receive all new change notifications.
167
168If you are frequently sending changes to the same parties and/or
169branches, consider adding a custom remote block to your project's
170`.git/config` file:
171
172====
173 $ cat .git/config
174 ...
175 [remote "for-a-exp"]
176 url = tr:kernel/common
Shawn O. Pearcefc0ec2f2009-05-28 11:20:06 -0700177 receivepack = git receive-pack --reviewer=a@a.com --cc=b@o.com
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800178 push = HEAD:refs/for/experimental
179
180 $ git push for-a-exp
181====
182
183
184git push: Replace Changes
185-------------------------
186
187To add an additional patch set to a change, replacing it with an
188updated version of the same logical modification, send the new
189commit to the change's ref. For example, to add the commit whose
190SHA-1 starts with `c0ffee` as a new patch set for change number
191`1979`, use the push refspec `c0ffee:refs/changes/1979` as below:
192
193====
194 git push ssh://sshusername@hostname:29418/projectname c0ffee:refs/changes/1979
195====
196
197This form can be combined together with `refs/for/'branchname'`
198(above) to simultaneously create new changes and replace changes
199during one network transaction.
200
201For example, consider the following sequence of events:
202
203====
204 $ git commit -m A ; # create 3 commits
205 $ git commit -m B
206 $ git commit -m C
207
208 $ git push ... HEAD:refs/for/master ; # upload for review
209 ... A is 1500 ...
210 ... B is 1501 ...
211 ... C is 1502 ...
212
213 $ git rebase -i HEAD~3 ; # edit "A", insert D before B
214 ; # now series is A'-D-B'-C'
215 $ git push ...
216 HEAD:refs/for/master
217 HEAD~3:refs/changes/1500
218 HEAD~1:refs/changes/1501
219 HEAD~0:refs/changes/1502 ; # upload replacements
220====
221
222At the final step during the push Gerrit will attach A' as a new
223patch set on change 1500; B' as a new patch set on change 1501; C'
224as a new patch set on 1502; and D will be created as a new change.
225
226Ensuring D is created as a new change requires passing the refspec
227`HEAD:refs/for/branchname`, otherwise Gerrit will ignore D and
228won't do anything with it. For this reason it is a good idea to
229always include the create change refspec when uploading replacements.
230
231
232git push: Bypass Review
233-----------------------
234
235Changes (and annotated tags) can be pushed directly into a
236repository, bypassing the review process. This is primarily useful
237for a project owner to create new branches, create annotated tags
238for releases, or to force-update a branch whose history needed to
239be rewritten.
240
241Gerrit restricts direct pushes that bypass review to:
242
243* `refs/heads/*`: any branch can be updated, created, deleted,
244or rewritten by the pusher.
245* `refs/tags/*`: annotated tag objects pointing to any other type
246of Git object can be created. Tags cannot be updated or deleted.
247
248To push branches, the `Push Branch` project right must be granted
249to one (or more) of the user's groups. The allowed levels within
250this category are:
251
252* Update: Any existing branch can be fast-forwarded to a new commit.
253This is the safest mode as commits cannot be discarded. Creation
254of new branches is rejected.
255* Create: Implies Update, but also allows creation of a new branch
256if the name does not not already designate an existing branch name.
257* Delete: Implies Create and Update, but also allows an existing
258branch to be deleted. Since a force push is effectively a delete
259followed by a create, but performed atomically on the server and
260logged, this also permits forced push updates to branches.
261
262To push annotated tags, the `Push Annotated Tag` project right must
263be granted to one (or more) of the user's groups. There is only
264one level of access in this category.
265
266Project owners may wish to grant themselves `Push Annotated Tag`
267only at times when a new release is being prepared, and otherwise
268grant nothing at all. This ensures that accidental pushes don't
269make undesired changes to the public repository.
270
271
272Gritty Details
273--------------
274
275Gerrit requires that the tuple `('username', 'public_key')`
276be unique. When it gets a login request it scans all accounts
277whose SSH Username matches the name requested by the client, to
278see if any of them have the public key presented by the client.
279
280What this means is, say there's "john.doe@example.com" (me) and
281"john.doe@evil.com" (someone else - not me). Gerrit will consider
282both accounts' public keys when I login, but only binds the session
283to the account whose key was presented. If multiple accounts match
284the same key and same username, it denies the login.
285
286Given that most local names will be unique across a single Gerrit
287server, that means in practice most people will only be considering
288their own keys. Since SSH keys (in theory) are globally unique,
289even if two people have the same local name, they still can't access
290each other's accounts. But, if two people both used Debian's broken
291ssh-keygen and they have the same local name, they effectively lock
292each other out of Gerrit until one (or both) changes their key(s)
293to a more secure one.
294
295As Gerrit implements the entire SSH and Git server stack within its
296own process space, Gerrit maintains complete control over how the
297repository is updated, and what responses are sent to the `git push`
298client invoked by the end-user, or by `repo upload`. This allows
299Gerrit to provide magical refs, such as `refs/for/\*` for new
300change submission and `refs/changes/\*` for change replacement.
301When a push request is received to create a ref in one of these
302namespaces Gerrit performs its own logic to update the database,
303and then lies to the client about the result of the operation.
304A successful result causes the client to believe that Gerrit has
305created the ref, but in reality Gerrit hasn't created the ref at all.
306
307By implementing the entire server stack, Gerrit is also able to
308perform project level access control checks (to verify the end-user
309is permitted to access a project) prior to advertising the available
310refs, and potentially leaking information to a snooping client.
311Clients cannot tell the difference between 'project not found' and
312'project exists, but access is denied'.
313
314Gerrit can also ensure users have completed a valid Contributor
315Agreement prior to accepting any transferred objects, and if an
316agreement is required, but not completed, it aborts the network
317connection before data is sent. This ensures that project owners
318can be certain any object available in their repository has been
319supplied under at least one valid agreement.
Shawn O. Pearce5500e692009-05-28 15:55:01 -0700320
321GERRIT
322------
323Part of link:index.html[Gerrit Code Review]