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.
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:
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:
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:
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:
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:
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: