Working with oVirt Gerrit

Gerrit is a web-based code review system that uses the Git version control system. Gerrit makes it easy to review code by showing changes in a side by side display, allowing inline comments to be added by any reviewer. In the oVirt project we use Gerrit to review new commits. With Gerrit, it’s easy to add comments and suggestions, ask questions, and more. In the following sections you will find step-by-step directions for setting up Gerrit in your development environment.

To get started, go to

  1. Working with oVirt Gerrit
    1. Registering as a User
    2. SSH Configuration
      1. Setting up SSH Keys
      2. Defining Gerrit in ~/.ssh/config
      3. Changing File Permissions
      4. Verifying the SSH Configuration
    3. Git Configuration and Procedures
      1. Cloning the oVirt-engine Repository
      2. Installing the change-ID Hook
      3. Configuring Git Personal Settings
      4. Configuring the Commit Template
      5. Configuring the Git Commit Spell Check, Syntax Highlighting and Maxwidth
      6. Rebasing
    4. Pushing a Patch for Review
      1. Pushing or Updating a Draft Using the Git Review Plugin
    5. The Track Patch Review Process
      1. A Summary of the Process
      2. The Process in Detail
      3. Submitting a Topic Branch to Gerrit

Registering as a User

You can register as a user with any OpenID provider. Alternatively, sign in with:

  • GitHub or Google OAuth 2.0
  • Your Launchpad or Yahoo IDs
  • Any fedora FAS account, using: <username>

Once you log in, choose a Gerrit username. This username will be used to generate an HTTP password (Settings –> HTTP Password) and to enable SSH connection.

To choose username:

  • Go to Settings
  • Enter your username in the username field and click Save Changes

SSH Configuration

Setting up SSH Keys

If you don’t have a set of SSH keys, open the terminal on your local machine and enter the following:

  ssh-keygen -t rsa

Ensure that your private RSA key is located at ~/.ssh and that the permissions on the .ssh directory are sufficiently restrictive. Typically, the .ssh directory should have permissions set to 700, and the file .ssh/id_rsa should have the permissions set to 600.

To allow SSH to access Gerrit, update the SSH public key via Gerrit settings:

  • In the top right corner, click your username, and select Settings > SSH public keys.
  • Copy and paste the contents of your public key file (typically ~/.ssh/ into the provided text box.

Defining Gerrit in ~/.ssh/config

     Port 29418
     User <your_gerrit_username>

Changing File Permissions

  chmod 600 ~/.ssh/config

Verifying the SSH Configuration


If SSH is configured correctly, you will see the following message:

  ***    Welcome to Gerrit Code Review    ****

Git Configuration and Procedures

Cloning the oVirt-engine Repository

  git clone

For a read-only repository, this can also be done using:

  git clone git://

Installing the change-ID Hook

You must do this before you commit anything In order to easily track commit changes in Gerrit, each commit must have a change-ID. This change-ID is added automatically via a Git hook. To install this hook, enter:

  cd ovirt-engine
  scp -p .git/hooks/

Or alternatively without need of authentication:

  wget -P .git/hooks

ATTENTION: All of the ovirt projects require a Signed-off-by (SOB), add the following lines in the end of .git/hooks/commit-msg, after the line “add_ChangeId”:

  SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
  grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

Allow the hook to be executed:

  chmod a+x .git/hooks/commit-msg

Note: If you commit something before you do the above, you can add the Change-ID and signed-off-by lines by:

  git commit --amend -s

Configuring Git Personal Settings

  git config --global "John Doe"
  git config --global

Configuring the Commit Template

  cd ovirt-engine
  git config commit.template config/engine-commit-template.txt

NOTE: Alternatively, if you’re contributing to other projects than ovirt-engine try looking for template in it’s git tree instead.

Configuring the Git Commit Spell Check, Syntax Highlighting and Maxwidth

  # edit ~/.vimrc
  syntax on
  filetype plugin indent on
  autocmd Filetype gitcommit setlocal spell textwidth=72


  git fetch -v
  git rebase origin/master

Pushing a Patch for Review


  git push HEAD:refs/for/master

Alternatively, assuming your remote repository is ‘origin’, enter:

  git push origin HEAD:refs/for/master

Pushing or Updating a Draft Using the Git Review Plugin

The git-review plugin is optional.

To push or update a draft, enter:

  git review -D -r origin master

To push or update a published patch:

  git review -r origin master

The Track Patch Review Process

A Summary of the Process

The patch life cycle process comprises of the following steps:

  1. ‎The patch is checked
    • Verification (Verified+1): bug fixes or new functionality should be verified by a real person
    • Maintainer review and approval (Code-Review+2)
    • Publishing. This triggers Continuous Integration (CI)
  2. CI tests passed (Continuous-Integration+1)
  3. Patch merged by maintainer

The Process in Detail

  • Anyone can send a patch
    • Initially a patch should be sent as draft
  • Code-Review - human code review:
  • A human code review can result in “Code-Review” flag set to:
      • +2 - Looks good to me, approved
      • +1 - Looks good to me, but someone else must approve
      • 0 - No score
      • -1 - I would prefer that you didn’t submit this
      • -2 - Do not submit
    • Anyone can set Code-Review flag to +1/-1 and comment on the patch. This helps maintainers in reviewing the patches
    • Only maintainer(s) can set Code-Review flag to +2, which is required to commit (submit) it
  • Verified - human verified
    • Somebody (can be anyone) needs to confirm they checked the patch works and set “Verified” flag to +1
    • this doesn’t have to be the developer
    • this does not have to be done fully manually, but human must verify
  • Automated tests by continuous integration:
    • After humans have:
      • set Code-Review +2
      • confirmed the patch is ready and has Verified +1
    • The developer should publish the draft patch:
      • Visit the patch page with your browser
      • Press on the button “Publish” in the web view of your patch
    • After “Verified” flag is +1 and the patch is published, CI Runs on patch set updates:
      • CI sets “Continuous-Integration” flag to:
        • +1 if the patch passes CI tests
        • -1 if the patch fails CI tests
  • The maintainer(s) can submit (commit) the patch when it has: * Code-Review: +2
    • Verified: +1
    • Continuous-Integration: +1
  • NACK-ed (-1/-2) patches should not be submitted
  • A submitted patch is automatically merged to the git repository
  • When uploading a new patch set, the contributor should also add a review comment of the changes from previous version, to help reviewers track and review the changes (unless Gerrit itself added a comment that a rebase is needed, and in that case no new comment is needed).

Submitting a Topic Branch to Gerrit

A topic branch is a short-lived branch that you create and use for a single particular feature or related work.

  • First, install the git-review tool
    • git-review is a tool that helps submitting git branches to Gerrit for review.


    $ dnf install git-review
  • Setting git-review:

    git-review, by default, looks for a git remote called gerrit, and submits the current branch to HEAD:refs/for/master at that remote. If the “gerrit” remote does not exist, git-review looks for a file called .gitreview at the root of the repository with information about the gerrit remote. Assuming that file is present, git-review should be able to automatically configure your repository the first time it is run.

  • Example: project/.git/config


  [remote "gerrit"]
    url =
    pushurl = ssh://
    fetch = +refs/heads/*:refs/remotes/gerrit/* 
  • Execute git-review setup


    $project> git review -s 
  • Create your local branch feature


    $project> git checkout -b engine-register 
  • Check if you are under branch


    $project> git branch
    * engine-register
  • Execute the changes and commit it


    $project> vi
    $project> git add
    $project> git commit  
  • Submit the topic branch changes to gerrit


    $project>git review -t engine-register
    remote: Resolving deltas:   0% (0/3)
    remote: (W) fba45fe: no files changed, message updated
    To ssh://
   * [new branch]      HEAD -> refs/for/master/engine-register 
  • Now go to the gerrit url for your change and note that the topic field is changed to your topic branch name.