How to git-pull a given patch set from Gerrit?

This feature is standard in the Gerrit UI.

On the top right of the UI for a patch, click Download, and you will see something like:

Gerrit Change Screen Download

When you are navigating the patches you go to the download section and copy the command line command for checking out the patch set, for example like this:

git fetch https://gerrit.googlesource.com/gerrit refs/changes/03/64403/2 && git checkout FETCH_HEAD

Then I normally create a branch with the review number and patchset as name

git checkout -b b64403-2

For here you can work normally and commit your changes or cherry-pick/rebase your changes on this change.

Once the review of r64403 is done your code can be merged or when there is another patchset submitted you will need to do the same thing again.

If you do not see the options to download the option to Checkout or Cherry Pick you need to edit the gerrit.config, something like this:

[download]
    scheme = ssh
    command = checkout
    command = cherry_pick

More details can be found in the Gerrit Documentation


Update: As barryku correctly points out, in the later version you need to download the downloads-commands plugin. This can be done during the initial setup or by using the following command:

java -jar gerrit-2.11.4.war init -d review_site --batch --install-plugin download-commands

Or you can use the -d option to git-review. For example, assuming you were working the with nova-docker repository and were interested in this change in gerrit:

  • https://review.openstack.org/#/c/148486/

You could download the latest patchset like this:

git review -d 148486

Or you can use the change id:

git review -d I35729a86e211391f67cc959d19416c9125c6f9eb

You can also request a specific revision of the patch by appending a comma and the patch number. E.g, to get the second revision of that patch:

git review -d 148486,2