Git is a free and open source distributed version control system. Distributed means that there is no central copy of the repository. It's used worldwide by big and small open-source projects, like KDE, Linux, Gnome and so on.
What you'll learn
How to install and configure Git.
How to use Gerrit for code review.
What you need
A computer running GNU/Linux, Mac OS X or Windows.
Internet connection.
In order to use Git, you need to install it! In GNU/Linux, it might be installed. Skip the steps that aren't for your current operating system.
Install Git & git-review in GNU/Linux
To install Git in Debian-based distributions, you need to run the following command:
sudo apt install git git-review
For other Linux distributions, use the proper package manager.
Install Git & git-review in Mac OS X
The best way to install Git is using the Homebrew package manager:
brew install git git-review
Install Git & git-review in Windows
One of the easier ways to use Git on Windows is using Git for Windows.
When you register changes in a Git repository, they are signed with your name and email address, to know who has made each change. For this purpose, you need to configure Git before use it. Run these two commands, using your name and email address:
A SSH keys is used to establish a secure connection between your computer and Gerrit. You need to create it in order to connect to the Gerrit instance.
Create an SSH key
Check that you haven't any SSH key. If there's a file called id_rsa in your .ssh directory, you don't need to create a new one.
ls ~/.ssh
Generate a new SSH key with the following command. Don't forget to use you email address.
ssh-keygen -t rsa -C "example@example.com"
Accept the default values and enter a strong passphrase.
Add the SSH key to Gerrit in Wikimedia
Create a Wikimedia developer account at wikitech.wikimedia.org if you do not yet have one. Your account's username and password will be the same for Gerrit.
Log into the web interface for Gerrit.
Click on your username in the top right corner, then choose Settings.
Click SSH Public Keys in the menu on the left.
Paste the content of your SSH Public Key (file ~/.ssh/id_rsa.pub) into the corresponding field and click Add.
Test that SSH works fine
Check that you can connect to the gerrit instance of Wikimedia running the following command, replacing username with yours.
ssh -p 29418 username@gerrit.wikimedia.org
It should give a Gerrit welcome message and then abort.
You have installed and configured Git and git-review to use with Gerrit. Now you can submit patches to the repositories. You need a Developer account in order to do this.
Download the repository
Clone the repository that you need using git clone (replace username):
Create a branch to work in, replacing BRANCHNAME with a short but descriptive name for the branch.
git checkout -b BRANCHNAME origin/master
Commit the changes
Now you can work on the task or patch that you plan to do. When you are ready, submit the patch:
Check the files that you've modified with the following command:
git status
Add the files that you want to commit:
git add file1 file2
Once you are happy with the change list, you can add them to your local repository by using:
git commit
You will then be asked in your text editor to add a descriptive message for the commit message. Make sure that you follow the Commit message guidelines. This is what other people will see when you will later push that commit to the repository. Don't forget to add in the last line a Bug reference if it's necessary:
Bug: T999999
Push to the repository
It's a good idea to synchronize your changeset with any changes that may have occurred in master while you've been working ("rebasing"). From within the branch you've been working on, execute the following command:
git pull --rebase origin master
Now you can push the changes to Gerrit:
git review -R
Congratulations! You have sent a patch to Gerrit and hopefully will get reviewed soon!
If you want to learn more about the topics that we've covered in this codelab, take a look to this resources: