blob: 67799e4bedcfbe0e3a0fbc294e464c405092855e [file] [log] [blame]
Shawn O. Pearcee31d02c2009-12-08 12:21:37 -08001Gerrit Code Review - Uploading Changes
2======================================
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -08003
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -07004Gerrit supports three methods of uploading changes:
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -08005
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
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070010All three methods rely on SSH public key authentication, which must
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080011first be configured by the uploading user.
12
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070013SSH
14---
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080015
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070016Each user uploading changes to Gerrit must configure one or more SSH
17public keys. The per-user SSH key list can be accessed over the web
Edwin Kempinb5df3b82011-10-10 11:31:14 +020018within Gerrit by `Settings`, and then accessing the `SSH Public Keys`
19tab.
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080020
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070021[[configure_ssh]]
22Configuration
23~~~~~~~~~~~~~
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080024
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070025To register a new SSH key for use with Gerrit, paste the contents of
26your `id_rsa.pub` or `id_dsa.pub` file into the text box and click
27the add button. Gerrit only understands SSH version 2 public keys.
28Keys may be supplied in either the OpenSSH format (key starts with
29`ssh-rsa` or `ssh-dss`) or the RFC 4716 format (file starts with
30`---- BEGIN SSH2 PUBLIC KEY ----`).
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080031
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070032Typically SSH keys are stored in your home directory, under `~/.ssh`.
33If you don't have any keys yet, you can create a new one and protect
34it with a passphrase:
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080035
36====
37 ssh-keygen -t rsa
38====
39
40Then copy the content of the public key file onto your clipboard,
41and paste it into Gerrit's web interface:
42
43====
44 cat ~/.ssh/id_rsa.pub
45====
46
47[TIP]
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070048Users who frequently upload changes will also want to consider
David Pursehouse221d4f62012-06-08 17:38:08 +090049starting an `ssh-agent`, and adding their private key to the list
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070050managed by the agent, to reduce the frequency of entering the
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080051key's passphrase. Consult `man ssh-agent`, or your SSH client's
52documentation, for more details on configuration of the agent
53process and how to add the private key.
54
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070055[[test_ssh]]
56Testing Connections
57~~~~~~~~~~~~~~~~~~~
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080058
59To verify your SSH key is working correctly, try using an SSH client
David Pursehouse221d4f62012-06-08 17:38:08 +090060to connect to Gerrit's SSHD port. By default Gerrit runs on
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080061port 29418, using the same hostname as the web server:
62
63====
Edwin Kempinfb95a1b2011-10-05 10:08:00 +020064..................................................................
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080065 $ ssh -p 29418 sshusername@hostname
Edwin Kempinfb95a1b2011-10-05 10:08:00 +020066
67 **** Welcome to Gerrit Code Review ****
68
69 Hi John Doe, you have successfully connected over SSH.
70
71 Unfortunately, interactive shells are disabled.
72 To clone a hosted Git repository, use:
73
74 git clone ssh://sshusername@hostname:29418/REPOSITORY_NAME.git
75
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080076 Connection to hostname closed.
Edwin Kempinfb95a1b2011-10-05 10:08:00 +020077..................................................................
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080078====
79
Edwin Kempinfb95a1b2011-10-05 10:08:00 +020080In the command above, `sshusername` was configured as `Username` on
81the `Profile` tab of the `Settings` screen. If it is not set,
82propose a name and use `Select Username` to select the name.
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080083
84To determine the port number Gerrit is running on, visit the special
85information URL `http://'hostname'/ssh_info`, and copy the port
86number from the second field:
87
88====
89 $ curl http://hostname/ssh_info
90 hostname 29418
91====
92
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080093If you are developing an automated tool to perform uploads to Gerrit,
94let the user supply the hostname or the web address for Gerrit,
95and obtain the port number on the fly from the `/ssh_info` URL.
96The returned output from this URL is always `'hostname' SP 'port'`,
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070097or `NOT_AVAILABLE` if the SSHD server is not currently running.
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -080098
99
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700100git push
101--------
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800102
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700103[[push_create]]
104Create Changes
105~~~~~~~~~~~~~~
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800106
David Pursehouse221d4f62012-06-08 17:38:08 +0900107To create new changes for review, simply push to the project's
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800108magical `refs/for/'branch'` ref using any Git client tool:
109
110====
111 git push ssh://sshusername@hostname:29418/projectname HEAD:refs/for/branchname
112====
113
114E.g. `john.doe` can use git push to upload new changes for the
115`experimental` branch of project `kernel/common`, hosted at the
116`git.example.com` Gerrit server:
117
118====
119 git push ssh://john.doe@git.example.com:29418/kernel/common HEAD:refs/for/experimental
120====
121
122Each new commit uploaded by the `git push` client will be
123converted into a change record on the server. The remote ref
124`refs/for/experimental` is not actually created by Gerrit, even
125though the client's status messages may say otherwise.
126
127Other users (e.g. project owners) who have configured Gerrit to
128notify them of new changes will be automatically sent an email
129message when the push is completed.
130
Shawn O. Pearced50c94e2010-07-15 12:24:11 -0700131To include a short tag associated with all of the changes in the
132same group, such as the local topic branch name, append it after
133the destination branch name. In this example the short topic tag
134'driver/i42' will be saved on each change this push creates or
135updates:
136
137====
138 git push ssh://john.doe@git.example.com:29418/kernel/common HEAD:refs/for/experimental/driver/i42
139====
140
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800141If you are frequently uploading changes to the same Gerrit server,
142consider adding an SSH host block in `~/.ssh/config` to remember
143your username, hostname and port number. This permits the use of
144shorter URLs on the command line, such as:
145
146====
147 $ cat ~/.ssh/config
148 ...
149 Host tr
150 Hostname git.example.com
151 Port 29418
152 User john.doe
153
154 $ git push tr:kernel/common HEAD:refs/for/experimental
155====
156
Edwin Kempinb5df3b82011-10-10 11:31:14 +0200157Specific reviewers can be requested and/or additional 'carbon
158copies' of the notification message may be sent by including these
Shawn O. Pearcefc0ec2f2009-05-28 11:20:06 -0700159as arguments to `git receive-pack`:
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800160
161====
Shawn O. Pearcefc0ec2f2009-05-28 11:20:06 -0700162 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 -0800163====
164
Edwin Kempincdb0e002011-09-08 14:23:30 +0200165The `--reviewer='email'` and `--cc='email'` options may be
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800166specified as many times as necessary to cover all interested
167parties. Gerrit will automatically avoid sending duplicate email
168notifications, such as if one of the specified reviewers or CC
169addresses had also requested to receive all new change notifications.
170
171If you are frequently sending changes to the same parties and/or
172branches, consider adding a custom remote block to your project's
173`.git/config` file:
174
175====
176 $ cat .git/config
177 ...
178 [remote "for-a-exp"]
179 url = tr:kernel/common
Shawn O. Pearcefc0ec2f2009-05-28 11:20:06 -0700180 receivepack = git receive-pack --reviewer=a@a.com --cc=b@o.com
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800181 push = HEAD:refs/for/experimental
182
183 $ git push for-a-exp
184====
185
186
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700187[[push_replace]]
188Replace Changes
189~~~~~~~~~~~~~~~
190
191To add an additional patch set to a change, ensure Change-Id
192lines were created in the original commit messages, and just use
193`git push URL HEAD:refs/for/...` as <<push_create,described above>>.
194Gerrit Code Review will automatically match the commits back to
195their original changes by taking advantage of the Change-Id lines.
196
197If Change-Id lines are not present in the commit messages, consider
198amending the message and copying the line from the change's page
199on the web, and then using `git push` as described above.
200
201If Change-Id lines are not available, then the user must use the
202manual mapping technique described below.
203
204For more about Change-Ids, see link:user-changeid.html[Change-Id Lines].
205
Edwin Kempin930187e2011-01-27 10:13:42 +0100206[[manual_replacement_mapping]]
Edwin Kempinb2e42c82011-01-13 09:29:57 +0100207Manual Replacement Mapping
208^^^^^^^^^^^^^^^^^^^^^^^^^^
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700209
210.Deprecation Warning
211****
212The remainder of this section describes a manual method of replacing
213changes by matching each commit name to an existing change number.
214End-users should instead prefer to use Change-Id lines in their
215commit messages, as the process is then fully automated by Gerrit
216during normal uploads.
217
218See above for the preferred technique of replacing changes.
219****
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800220
221To add an additional patch set to a change, replacing it with an
222updated version of the same logical modification, send the new
223commit to the change's ref. For example, to add the commit whose
224SHA-1 starts with `c0ffee` as a new patch set for change number
225`1979`, use the push refspec `c0ffee:refs/changes/1979` as below:
226
227====
228 git push ssh://sshusername@hostname:29418/projectname c0ffee:refs/changes/1979
229====
230
231This form can be combined together with `refs/for/'branchname'`
232(above) to simultaneously create new changes and replace changes
233during one network transaction.
234
235For example, consider the following sequence of events:
236
237====
238 $ git commit -m A ; # create 3 commits
239 $ git commit -m B
240 $ git commit -m C
241
242 $ git push ... HEAD:refs/for/master ; # upload for review
243 ... A is 1500 ...
244 ... B is 1501 ...
245 ... C is 1502 ...
246
247 $ git rebase -i HEAD~3 ; # edit "A", insert D before B
248 ; # now series is A'-D-B'-C'
Shawn O. Pearced6078462009-11-02 10:37:01 -0800249 $ git push ...
250 HEAD:refs/for/master
251 HEAD~3:refs/changes/1500
252 HEAD~1:refs/changes/1501
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800253 HEAD~0:refs/changes/1502 ; # upload replacements
254====
255
256At the final step during the push Gerrit will attach A' as a new
257patch set on change 1500; B' as a new patch set on change 1501; C'
258as a new patch set on 1502; and D will be created as a new change.
259
260Ensuring D is created as a new change requires passing the refspec
261`HEAD:refs/for/branchname`, otherwise Gerrit will ignore D and
262won't do anything with it. For this reason it is a good idea to
263always include the create change refspec when uploading replacements.
264
265
Edwin Kempin913eab12011-05-06 08:18:24 +0200266[[bypass_review]]
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700267Bypass Review
268~~~~~~~~~~~~~
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800269
270Changes (and annotated tags) can be pushed directly into a
271repository, bypassing the review process. This is primarily useful
272for a project owner to create new branches, create annotated tags
273for releases, or to force-update a branch whose history needed to
274be rewritten.
275
276Gerrit restricts direct pushes that bypass review to:
277
278* `refs/heads/*`: any branch can be updated, created, deleted,
279or rewritten by the pusher.
280* `refs/tags/*`: annotated tag objects pointing to any other type
Nico Sallembien950e4152010-03-16 15:45:33 -0700281of Git object can be created.
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800282
Fredrik Luthanderc10f9e72012-01-23 17:00:45 +0100283To push branches, the proper access rights must be configured first.
284Here follows a few examples of how to configure this in Gerrit:
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800285
286* Update: Any existing branch can be fast-forwarded to a new commit.
287This is the safest mode as commits cannot be discarded. Creation
Fredrik Luthanderc10f9e72012-01-23 17:00:45 +0100288of new branches is rejected. Can be configured with
289link:access-control.html#category_push_direct['Push'] access.
290* Create: Allows creation of a new branch if the name does not
291already designate an existing branch name. Needs
292link:access-control.html#category_create['Create Reference']
293configured. Please note that once created, this permission doesn't
294grant the right to update the branch with further commits (see above
295for update details).
296* Delete: Implies Update, but also allows an existing
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800297branch to be deleted. Since a force push is effectively a delete
298followed by a create, but performed atomically on the server and
299logged, this also permits forced push updates to branches.
Fredrik Luthanderc10f9e72012-01-23 17:00:45 +0100300To grant this access, configure
301link:access-control.html#category_push_direct['Push'] with the
302'Force' option ticked.
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800303
304To push annotated tags, the `Push Annotated Tag` project right must
305be granted to one (or more) of the user's groups. There is only
306one level of access in this category.
307
308Project owners may wish to grant themselves `Push Annotated Tag`
309only at times when a new release is being prepared, and otherwise
310grant nothing at all. This ensures that accidental pushes don't
311make undesired changes to the public repository.
312
313
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700314repo upload
315-----------
316
317repo is a multiple repository management tool, most commonly
318used by the Android Open Source Project. For more details, see
319link:http://source.android.com/download/using-repo[using repo].
320
321[[repo_create]]
322Create Changes
323~~~~~~~~~~~~~~
324
325To upload changes to a project using `repo`, ensure the manifest's
326review field has been configured to point to the Gerrit server.
327Only the hostname or the web address needs to be given in the
328manifest file. During upload `repo` will automatically determine the
329correct port number by reading `http://'reviewhostname'/ssh_info`
330when its invoked.
331
332Each new commit uploaded by `repo upload` will be converted into
333a change record on the server. Other users (e.g. project owners)
334who have configured Gerrit to notify them of new changes will be
335automatically sent an email message. Additional notifications can
336be sent through command line options.
337
338For more details on using `repo upload`, see `repo help upload`.
339
340[[repo_replace]]
341Replace Changes
342~~~~~~~~~~~~~~~
343
344To replace changes, ensure Change-Id lines were created in the
Cecilia Svenssoncd2491d2012-01-20 14:22:30 +0100345commit messages, and just use `repo upload`.
346Gerrit Code Review will automatically match the commits back to
347their original changes by taking advantage of their Change-Id lines.
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700348
349If Change-Id lines are not present in the commit messages, consider
350amending the message and copying the line from the change's page
351on the web.
352
353If Change-Id lines are not available, then the user must use the much
Cecilia Svenssoncd2491d2012-01-20 14:22:30 +0100354more <<manual_replacement_mapping,manual mapping technique>> offered
355by using `git push` to a specific `refs/changes/change#` reference.
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700356
357For more about Change-Ids, see link:user-changeid.html[Change-Id Lines].
358
359
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800360Gritty Details
361--------------
362
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800363As Gerrit implements the entire SSH and Git server stack within its
364own process space, Gerrit maintains complete control over how the
365repository is updated, and what responses are sent to the `git push`
366client invoked by the end-user, or by `repo upload`. This allows
Edwin Kempincdb0e002011-09-08 14:23:30 +0200367Gerrit to provide magical refs, such as `refs/for/*` for new
368change submission and `refs/changes/*` for change replacement.
Shawn O. Pearcee61a3c62009-01-29 08:42:41 -0800369When a push request is received to create a ref in one of these
370namespaces Gerrit performs its own logic to update the database,
371and then lies to the client about the result of the operation.
372A successful result causes the client to believe that Gerrit has
373created the ref, but in reality Gerrit hasn't created the ref at all.
374
375By implementing the entire server stack, Gerrit is also able to
376perform project level access control checks (to verify the end-user
377is permitted to access a project) prior to advertising the available
378refs, and potentially leaking information to a snooping client.
379Clients cannot tell the difference between 'project not found' and
380'project exists, but access is denied'.
381
382Gerrit can also ensure users have completed a valid Contributor
383Agreement prior to accepting any transferred objects, and if an
384agreement is required, but not completed, it aborts the network
385connection before data is sent. This ensures that project owners
386can be certain any object available in their repository has been
387supplied under at least one valid agreement.
Shawn O. Pearce5500e692009-05-28 15:55:01 -0700388
389GERRIT
390------
391Part of link:index.html[Gerrit Code Review]