[XDA-University] v_superuser:
So firstly, I'll explain few terms that are important for you to learn before going towards a bit tricky side. ;)​

Git

- To be precise, git is a code-sharing website/software that allows you to share your project resources you can 'Make Software, better, together'(That's what the tag line says :p )!

Now, before I go to gerrit, read this: Major Open Source Projects, like, CyanogenMod, AOKP, OmniROM etc. don't directly accept pull requests and in case you want to make a change in their source for a fix/feature or anything, you need to send them patches over gerrit which are then reviewed by the trusted members of the community and if they find it valuable enough, gets merged into the git repository!

Gerrit

(Copying the definition from Wiki) - Gerrit is a free, web-based team software code review tool. Software developers in a team can review each other's modifications on their source code using a Web browser and approve or reject those changes. It integrates closely with Git, a distributed version control system.

So, now, git and gerrit are so closely related, that a patch verified over gerrit can directly be merged on git without much hassel, also please note that your gerrit and git username must be same.

Pull Requests

- Pull requests are sent over Git after you fork a repository, make some changes into it and then want the owner to merge those changes into his repository, and that's how community development and Open Source works. :)

Patches

- In simple terms, any changes you make to repos of Open Source Projects like CM or AOKP and send them over gerrit for code review are called Patches.

How GERRIT works?! :confused:​

Now, Gerrit is deployed in place of this central repository and adds an additional concept, a store of pending changes. Everyone still fetches from the authoritative repository but instead of pushing back to it, they push to this pending changes location. A change can only be submitted into the authoritative repository and become an accepted part of the project once the change has been reviewed and approved.

I found a nice diagram explaining this over the internet that will clear your doubts(if any :p) :) -

Now few important stuff needs to be setup before proceeding-

​

Setting up Git:

Debian/Ubuntu:

sudo apt-get install git

Fedora:

yum install git

ArchLinux:

pacman -S git

openSUSE:

zypper install git

Configuring git:

git config --global user.email "your-email@domain.com"

git config --global user.name "your-username"

Setting up SSH Keys(Skip this if you have already set them up) -

cd .ssh
ssh-keygen -t rsa -C "your-email@domain.com"

Now this will create 2 files in ~/.ssh directory as follows:

Adding SSH Keys to your Account -

cat /home/username_on_pc/.ssh/id_rsa.pub

This will show up few lines over terminal, copy those and add them into your git profile(I won't explain that, there are many guides for the same) ;)

Now install few packages -

sudo apt-get install python-pip
sudo pip install git-review

Now comes setting up the Gerrit part :D -​

In case of CyanogenMod,

git config --global review.review.cyanogenmod.org.username "gerrit username"
git config --global review.review.cyanogenmod.org.email "email you registered with"

In case of AOKP,

git config --global review.gerrit.aokp.co.username <gerrit username>
git config --global review.gerrit.aokp.co.email <email you registered with>

Making Changes and Submitting Patches :D -

​

I'd firstly recommend you to repo sync to grab the full latest source.

Next(Don't make changes before this step) -

repo start <branch> <path to make changes

Example(You need to be in the source directory) -

repo start kitkat packages/apps/Settings

Now after this, go into the folders, make your changes and save them but only the changes in the specified directories(Packages/apps/Settings in this case)!

then

cd packages/apps/Settings

After making changes, for satisfaction, run,

git status

It tells you what files you modified(In Red color ) and shows on which branch you're currently on. ;)

Now, the committing part,

Run:

git add -A

Run git status again, and it'll show the files in green color, telling you that the changes have been added. ;)

Now:

git commit -s

This will commit the changes and open up a Text Editor called NANO. Here you need to edit the commit message that appears at the side of the gerrit window to describe what the patch does. ;)

After writing the commit message, press Ctrl+O and then Enter key to save the commit message and then Ctrl+X to exit the editor. This is the committing part done. :D :good:

Now submitting the patch -

repo upload .

After this, it will ask you Yes/No twice(For the first time) and once(Everytime next) and you obviously have to hit Y!

Guess what?! Done! :D

Congratulations, you just learned gerrit and know how you use it. I hope you'll send some nice patches and respect the Open Source. :victory:

But, wait, what if there is a merge conflict :crying::crying:

Don't worry, there is a nic doc over the internet to help you with this - http://www.mediawiki.org/wiki/Gerrit/resolve_conflict

If you still have doubts, see few examples here or ask on the thread. I'll be happy to hrlp! :victory:

Credits -

> Firstly, My Parents :angel:

> [MENTION=4635923]galaxyfreak[/MENTION] [MENTION=4308696]championswimmer[/MENTION] [MENTION=4511965]crossfire77[/MENTION] to introducing me to gerrit. :p ;)

> AOKP/CM team for hosting useful docs.