Gerrit – Quick Guide

Gerrit – Quick Guide ”; Previous Next Gerrit – Overview Gerrit is a web based code review tool which is integrated with Git and built on top of Git version control system (helps developers to work together and maintain the history of their work). It allows to merge changes to Git repository when you are done with the code reviews. Gerrit was developed by Shawn Pearce at Google which is written in Java, Servlet, GWT(Google Web Toolkit). The stable release of Gerrit is 2.12.2 and published on March 11, 2016 licensed under Apache License v2. Why Use Gerrit? Following are certain reasons, why you should use Gerrit. You can easily find the error in the source code using Gerrit. You can work with Gerrit, if you have regular Git client; no need to install any Gerrit client. Gerrit can be used as an intermediate between developers and git repositories. Features of Gerrit Gerrit is a free and an open source Git version control system. The user interface of Gerrit is formed on Google Web Toolkit. It is a lightweight framework for reviewing every commit. Gerrit acts as a repository, which allows pushing the code and creates the review for your commit. Advantages of Gerrit Gerrit provides access control for Git repositories and web frontend for code review. You can push the code without using additional command line tools. Gerrit can allow or decline the permission on the repository level and down to the branch level. Gerrit is supported by Eclipse. Disadvantages of Gerrit Reviewing, verifying and resubmitting the code commits slows down the time to market. Gerrit can work only with Git. Gerrit is slow and it”s not possible to change the sort order in which changes are listed. You need administrator rights to add repository on Gerrit. Gerrit – Installation Before you can use Gerrit, you have to install Git and perform some basic configuration changes. Following are the steps to install Git client on different platforms. Installation of Git Client Linux You can install the Git on Linux by using the software package management tool. For instance, if you are using Fedora, you can use as − sudo yum install git If you are using Debian-based distribution such as Ubuntu, then use the following command − sudo apt-get install git Windows You can install Git on Windows by downloading it from the Git website. Just go to msysgit.github.io link and click on the download button. Mac Git can be installed on Mac using the following command − brew install git Another way of installing Git is, by downloading it from Git website. Just go to Git install on Mac link, which will install Git for Mac platform. Gerrit – Configure Git Once you have installed Git, you need to customize the configuration variables to add your personal information. You can get and set the configuration variables by using Git tool called git config along with the -l option (this option provides the current configuration). git config -l When you run the above command, you will get the configuration variables as shown in the following image You can change the customized information any time by using the commands again. In the next chapter, you will learn how to configure the user name and user Email by using git config command. Gerrit – Set Your Username & Email You can track each commit by setting name and email variables. The name variable specifies the name, while the email variable identifies the email address associated with Git commits. You can set these using the following commands − git config –global user.email “[email protected]” git config –global user.name “your_name” When you run the above commands, you will get the user name and email address as shown in the following image. Gerrit – Generate New SSH Key SSH stands for Secure Shell or sometimes Secure Socket Shell protocol used for accessing network services securely from a remote computer. You can set the SSH keys to provide a reliable connection between the computer and Gerrit. You can check the existing SSH key on your local computer using the following command in Git Bash − $ ls ~/.ssh After clicking the enter button, you will see the existing SSH key as shown in the following image − If you don”t find any existing SSH key, then you need to create a new SSH key. Generating New SSH Key You can generate a new SSH key for authentication using the following command in Git Bash − $ ssh-keygen -t rsa -C “[email protected]” If you already have a SSH key, then don”t a generate new key, as they will be overwritten. You can use ssh-keygen command, only if you have installed Git with Git Bash. When you run the above command, it will create 2 files in the ~/.ssh directory. ~/.ssh/id_rsa − It is private key or identification key. ~/.ssh/id_rsa.pub − It is a public tv. Gerrit – Add Your SSH Key You can add SSH key to the ssh-agent on different platforms discussed further. Linux Use the following command on Linux system to add SSH key cat /home/<local-user>/.ssh/id_rsa.pub Windows Open the GIT GUI and go to Help → Show SSH Key as shown in the following image. Then, click the Copy To Clipboard button, to copy the key to the clipboard. Mac In Mac OS X, you can copy id_rsa.pub contents to the clipboard using the following command. $ pbcopy < ~/.ssh/id_rsa.pub Gerrit – Add SSH Key to your Gerrit Account SSH key can be added to the Gerrit account using the following steps − Step 1 − First create an account at wmflabs.org services. Step 2 − Next sign in to the web interface for Gerrit. Step 3 − Then in the top right corner, click your username and select the Settings option. Here, we have created an account with the name John to make use of Gerrit Step 4 − Click the “SSH Public keys” option on the left-side menu and

Push your change set to Gerrit

Gerrit – Push Your Change Set to Gerrit ”; Previous Next You can submit the patches for review by using the git-review command. The change set can be pushed to Gerrit, by running the git review -R command as shown in the following screenshot. The -R option informs git-review not to complete rebase before submitting git changes to Gerrit. You can submit the code to other branch rather than the master, using the following command. git review name_of_branch It is also possible to submit the code to a different remote, using the following command. git review -r name_of_remote Print Page Previous Next Advertisements ”;

Download Extension Using Git

Gerrit – Download Examples Using Git ”; Previous Next You can download the example using Git along with the source code of any project organized at gerrit.wikimedia.org using the following Git Bash command. $ git clone ssh://<user_name>@gerrit.wikimedia.org:29418/sandbox The git clone command clones a directory into a new directory; in other words gets a copy of an existing repository. When you run the above command,it will clone the ”examples” repository and receives the objects, files, etc. from that repository and stores it in your local branch. Print Page Previous Next Advertisements ”;

Generate New SSH Key

Gerrit – Generate New SSH Key ”; Previous Next SSH stands for Secure Shell or sometimes Secure Socket Shell protocol used for accessing network services securely from a remote computer. You can set the SSH keys to provide a reliable connection between the computer and Gerrit. You can check the existing SSH key on your local computer using the following command in Git Bash − $ ls ~/.ssh After clicking the enter button, you will see the existing SSH key as shown in the following image − If you don”t find any existing SSH key, then you need to create a new SSH key. Generating New SSH Key You can generate a new SSH key for authentication using the following command in Git Bash − $ ssh-keygen -t rsa -C “[email protected]” If you already have a SSH key, then don”t a generate new key, as they will be overwritten. You can use ssh-keygen command, only if you have installed Git with Git Bash. When you run the above command, it will create 2 files in the ~/.ssh directory. ~/.ssh/id_rsa − It is private key or identification key. ~/.ssh/id_rsa.pub − It is a public tv. Print Page Previous Next Advertisements ”;

Gerrit – Discussion

Discuss Gerrit ”; Previous Next Gerrit is a web-based code review tool, which is integrated with Git and built on top of Git version control system (helps developers to work together and maintain the history of their work). It allows merging changes to Git repository when you are done with the code reviews. Print Page Previous Next Advertisements ”;

View the Change / Next Steps

Gerrit – View the Change / Next Steps ”; Previous Next The changes can be viewed in Gerrit dashboard by clicking in this link. Click the modified author name link, and you will get the following screenshot. Click the diffusion link to see the changed files with other details as shown in the following screenshot. Print Page Previous Next Advertisements ”;

Review Before Merge

Gerrit – Review before Merge ”; Previous Next Code review is an important part of the workflow in Gerrit. The basic concept is that the code must be reviewed before being merged. The workflow of the code for MediaWiki can be reviewed before merging it and also extensions can be reviewed which customizes the MediaWiki looks and works. There is one special case in which you can push the internationalization and localization commits. You can push all the commits to a remote branch when you finish the development. Someone will fetch the changes into local and merge those fetched changes into the local master by creating merge commit. You can push these changes to refs/for/master. Print Page Previous Next Advertisements ”;

Editing via the Web-Interface

Gerrit – Editing via the Web-Interface ”; Previous Next You can edit the project via the web interface after logging in to the Gerrit account as shown in the following steps. Step 1 − Go to Gerrit dashboard by clicking this link. You will get the following screenshot. Step 2 − Next click the mediawiki/extensions/examples link specified under Project column. Step 3 − Click the General link in the toolbar as shown in the following screenshot. Step 4 − When you open the General link, it will show a screenshot as the following. Step 5 − Click the Create Change button and it will open a popup window with some details as shown in the following screenshot. Step 6 − Enter the information and click the Create button. After creating the change, it will display the information as shown in the following screenshot. Step 7 − Click Edit and then click Add. Now select the file you want to edit. Here we have selected the file Example/i18n/en.json. When you open the file, it will show the json data as specified in the following screenshot. Step 8 − Click Save and then click the Close button. Step 9 − Finally click the Publish button to publish the edited file Step 10 − You can change commit message by clicking the Commit Message link as shown in the following screenshot. Step 11 − Press e on the keyboard and add some extra information, if you wish to Click Save and then click the Close button. Print Page Previous Next Advertisements ”;

Gerrit – Home

Gerrit Tutorial PDF Version Quick Guide Resources Job Search Discussion Gerrit is a web-based code review tool, which is integrated with Git and built on top of Git version control system (helps developers to work together and maintain the history of their work). It allows merging changes to Git repository when you are done with the code reviews. Audience This tutorial will help beginners learn the basic functionality of Gerrit tool. After completing this tutorial, you will find yourself at a moderate level of expertise in using Gerrit tool from where you can take yourself to the next levels. Prerequisites We assume that you are going to use Gerrit to handle all levels of Java and Non-Java projects. Hence, it will be good if you have some amount of exposure to software development life cycle and a working knowledge of developing web-based and non-webbased applications. Print Page Previous Next Advertisements ”;

Add Your SSH Key

Gerrit – Add Your SSH Key ”; Previous Next You can add SSH key to the ssh-agent on different platforms discussed further. Linux Use the following command on Linux system to add SSH key cat /home/<local-user>/.ssh/id_rsa.pub Windows Open the GIT GUI and go to Help → Show SSH Key as shown in the following image. Then, click the Copy To Clipboard button, to copy the key to the clipboard. Mac In Mac OS X, you can copy id_rsa.pub contents to the clipboard using the following command. $ pbcopy < ~/.ssh/id_rsa.pub Print Page Previous Next Advertisements ”;