[GUIDE] Understanding and using Gerrit [Easy+Explained]

Search This thread

v_superuser

Senior Member
Jan 3, 2013
485
1,492
25
Jammu
So, what happened to me in the past few days was that, I had to submit few patches to gerrit, and I had no idea what to do, where to start, and everything that runs in the mind of a person who first uses gerrit. One simply doesn't gets the whole knowledge he needs to use gerrit at one place, so I decided to make it, so it could be easier for the new users. :)

So firstly, I'll explain few terms that are important for you to learn before going towards a bit tricky side. ;)

  1. 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!
  2. 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.
  3. 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. :)
  4. 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) :) -

2lCom.png


Now few important stuff needs to be setup before proceeding-

Setting up Git:
Debian/Ubuntu:
Code:
sudo apt-get install git
Fedora:
Code:
yum install git
ArchLinux:
Code:
pacman -S git
openSUSE:
Code:
zypper install git

Configuring git:
Code:
git config --global user.email "your-email@domain.com"
Code:
git config --global user.name "your-username"

Setting up SSH Keys(Skip this if you have already set them up) -
Code:
cd .ssh
ssh-keygen -t rsa -C "your-email@domain.com"

Now this will create 2 files in ~/.ssh directory as follows:
~/.ssh/id_rsa //identification (private) key
~/.ssh/id_rsa.pub //public key

Adding SSH Keys to your Account -
Code:
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 -
Code:
sudo apt-get install python-pip
sudo pip install git-review

Now comes setting up the Gerrit part :D -

In case of CyanogenMod,
Code:
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,
Code:
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) -
Code:
repo start <branch> <path to make changes
Example(You need to be in the source directory) -
Code:
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
Code:
cd packages/apps/Settings
After making changes, for satisfaction, run,
Code:
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:
Code:
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:
Code:
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 -
Code:
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:
> @galaxyfreak @championswimmer @crossfire77 to introducing me to gerrit. :p ;)
> AOKP/CM team for hosting useful docs.
 
Last edited:

v_superuser

Senior Member
Jan 3, 2013
485
1,492
25
Jammu
Ok, so you have changes to make to the gerrit commit you just sent? Read on ;)

Ok, it goes easy,
repo start like earlier, make changes, go to the directory where the changes were made(Settings in this case). Now, make sure you go to the patch URL now and copy up the Change ID, which can be done by clicking over it.
Now, git status to spot the changes.
The,
Code:
git add -A
and
Code:
git commit --amend
^This will tell git that you need to amend an existing commit. Cool, isn't it? :cool:
Now, make changes(if any) to the commit message. and then
Code:
repo upload .

YES, That's it! The new change will now be at the same URL under Patch Set 2! And will got 3, 4 so on as you make changes. :p
 

solomonsunder

Member
Aug 18, 2013
6
1
Mumbai
Unable to patch

Ok, so you have changes to make to the gerrit commit you just sent? Read on ;)

Ok, it goes easy,
repo start like earlier, make changes, go to the directory where the changes were made(Settings in this case). Now, make sure you go to the patch URL now and copy up the Change ID, which can be done by clicking over it.
Now, git status to spot the changes.
The,
Code:
git add -A
and
Code:
git commit --amend
^This will tell git that you need to amend an existing commit. Cool, isn't it? :cool:
Now, make changes(if any) to the commit message. and then
Code:
repo upload .

YES, That's it! The new change will now be at the same URL under Patch Set 2! And will got 3, 4 so on as you make changes. :p

When I do the above commands to provide a patch to CyanogenMod gerrit it gives a new Change-ID and got committed as a new 'Merge Commit'. Can you tell me where I am going wrong? :crying:
 

solomonsunder

Member
Aug 18, 2013
6
1
Mumbai
patchset

You sure that you ran git commit --amend ?

Yes. I tried to follow your post and this one wiki.cyanogenmod.org/w/Doc:_using_gerrit. I did a change earlier here. review.cyanogenmod.org/#/c/59083/ for a new translation. Since there were whitespace errors and a file strings.xml~ got added, I changed my local file, deleted the strings.xml~, did a git add strings.xml. Then I did a git commit --amend which gave me a new Change-ID which said Merge commit 'refs/changes/83/59083/1' of review.cyanogenmod.org/CyanogenMod/android_frameworks_base into SystemUITamil. Then I did a repo upload. This got uploaded as review.cyanogenmod.org/#/c/59286/ :crying:

I tried to manually change the Change-ID to I52f02ea81fa7e20334e7ac7f26d37ced6fe54489 and then do a repo upload. But it didn't allow me and gave a message ! [remote rejected] SystemUITamil -> refs/for/cm-11.0 (squash commits first)

Where am I going wrong? :confused:
 
  • Like
Reactions: v_superuser

v_superuser

Senior Member
Jan 3, 2013
485
1,492
25
Jammu
I did a rebase on frameworks/base and then followed your steps. Now it is working fine. :good: I used to do a repo start branchname projectpath even for patches. Could that have been a reason it was creating new changes?

I never actually close the Terminal after submitting a patch and verifying it, :p so not sure, maybe it lost track of the changes you made and the change that got uploaded. Rebase is actually useful in this. :) :good: Glad that you figured it out.
 

v_superuser

Senior Member
Jan 3, 2013
485
1,492
25
Jammu
Says "Make sure you have correct rights" could be some rom specific stuff they have done for repo or seeing the rest, it could be something with your ssh keys.
You sure you're using same email id and username on git and gerrit?
 
  • Like
Reactions: Vivek_Neel

Nikhil

Senior Member
Sep 26, 2012
1,787
2,824
Ahmedabad
OnePlus 7 Pro
Xiaomi Poco X3 Pro
Says "Make sure you have correct rights" could be some rom specific stuff they have done for repo or seeing the rest, it could be something with your ssh keys.
You sure you're using same email id and username on git and gerrit?
No, username is different. Email id is same.
I cannot change either of them now.
I was able to connect via ssh using Nikhil@gerrit.aicp-rom.org (Nikhil is username in gerrit)
nikhilmenghani is my username in github.
Any thoughts?
 

Nikhil

Senior Member
Sep 26, 2012
1,787
2,824
Ahmedabad
OnePlus 7 Pro
Xiaomi Poco X3 Pro
@v_superuser

I tried again and facing the same error :(

Code:
Upload project frameworks/native/ to remote branch kitkat:
  branch kitkat ( 1 commit, Sat Oct 4 22:55:31 2014 +0530):
         8dd591e7 DisplayDevice: Backwards compatibility with old EGL
to gerrit.aicp-rom.com (y/N)? y
The authenticity of host '[gerrit.aicp-rom.com]:29418 ([195.154.174.249]:29418)' can't be established.
RSA key fingerprint is 8c:9c:82:a7:4e:4f:8c:c6:c3:21:3d:c0:38:5d:25:58.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[gerrit.aicp-rom.com]:29418,[195.154.174.249]:29418' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Any thoughts?
I added public key to gerrit.aicp-rom.com from id_rsa.pub file too.
 

v_superuser

Senior Member
Jan 3, 2013
485
1,492
25
Jammu
@v_superuser

I tried again and facing the same error :(

Code:
Upload project frameworks/native/ to remote branch kitkat:
  branch kitkat ( 1 commit, Sat Oct 4 22:55:31 2014 +0530):
         8dd591e7 DisplayDevice: Backwards compatibility with old EGL
to gerrit.aicp-rom.com (y/N)? y
The authenticity of host '[gerrit.aicp-rom.com]:29418 ([195.154.174.249]:29418)' can't be established.
RSA key fingerprint is 8c:9c:82:a7:4e:4f:8c:c6:c3:21:3d:c0:38:5d:25:58.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[gerrit.aicp-rom.com]:29418,[195.154.174.249]:29418' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Any thoughts?
I added public key to gerrit.aicp-rom.com from id_rsa.pub file too.

No idea. You registered on gerrit too, right?
 

khanxay

Member
Mar 24, 2015
12
8
Thank you OP for explainations. I see these termes (git, gerrit...) in lots of threats but never tried to understand. Now it's more clear in my head :p

Sent from my GT-I9305 using XDA Free mobile app
 

winxuser

Senior Member
Jan 15, 2012
2,961
2,341
Brisbane
Huawei Nexus 6P
Samsung Galaxy S9+
ok so i am starting to come along in my cm port for my phone, now i want to be able to upload the changes it gerrit for review,,

its for the i9305 s3,, now i have all the i9305 device tree setup for cm12.1 and its working pretty much 80% bugless..

if i go repo start it says error: project device/samsung/i9305 not found do i have to repo init the project before i can repo start

and as the s3 is officially supported up until kitkat syncing the cm12.1 source does not sync the device repos needed, would i need to repo clone the cm11 device tree and start a new branch for lollipop
 
Last edited:

marios199546

Senior Member
Dec 31, 2010
177
89
I want to upload a commit for a device kernel (for example Oneplus 3) to lineage . How to do it ? I have to download lineage source code ?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 57
    So, what happened to me in the past few days was that, I had to submit few patches to gerrit, and I had no idea what to do, where to start, and everything that runs in the mind of a person who first uses gerrit. One simply doesn't gets the whole knowledge he needs to use gerrit at one place, so I decided to make it, so it could be easier for the new users. :)

    So firstly, I'll explain few terms that are important for you to learn before going towards a bit tricky side. ;)

    1. 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!
    2. 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.
    3. 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. :)
    4. 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) :) -

    2lCom.png


    Now few important stuff needs to be setup before proceeding-

    Setting up Git:
    Debian/Ubuntu:
    Code:
    sudo apt-get install git
    Fedora:
    Code:
    yum install git
    ArchLinux:
    Code:
    pacman -S git
    openSUSE:
    Code:
    zypper install git

    Configuring git:
    Code:
    git config --global user.email "your-email@domain.com"
    Code:
    git config --global user.name "your-username"

    Setting up SSH Keys(Skip this if you have already set them up) -
    Code:
    cd .ssh
    ssh-keygen -t rsa -C "your-email@domain.com"

    Now this will create 2 files in ~/.ssh directory as follows:
    ~/.ssh/id_rsa //identification (private) key
    ~/.ssh/id_rsa.pub //public key

    Adding SSH Keys to your Account -
    Code:
    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 -
    Code:
    sudo apt-get install python-pip
    sudo pip install git-review

    Now comes setting up the Gerrit part :D -

    In case of CyanogenMod,
    Code:
    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,
    Code:
    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) -
    Code:
    repo start <branch> <path to make changes
    Example(You need to be in the source directory) -
    Code:
    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
    Code:
    cd packages/apps/Settings
    After making changes, for satisfaction, run,
    Code:
    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:
    Code:
    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:
    Code:
    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 -
    Code:
    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:
    > @galaxyfreak @championswimmer @crossfire77 to introducing me to gerrit. :p ;)
    > AOKP/CM team for hosting useful docs.
    18
    Ok, so you have changes to make to the gerrit commit you just sent? Read on ;)

    Ok, it goes easy,
    repo start like earlier, make changes, go to the directory where the changes were made(Settings in this case). Now, make sure you go to the patch URL now and copy up the Change ID, which can be done by clicking over it.
    Now, git status to spot the changes.
    The,
    Code:
    git add -A
    and
    Code:
    git commit --amend
    ^This will tell git that you need to amend an existing commit. Cool, isn't it? :cool:
    Now, make changes(if any) to the commit message. and then
    Code:
    repo upload .

    YES, That's it! The new change will now be at the same URL under Patch Set 2! And will got 3, 4 so on as you make changes. :p
    4
    Great work !

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

    Here are the configs required for omnirom.
    2
    @v_superuser

    I tried again and facing the same error :(

    Code:
    Upload project frameworks/native/ to remote branch kitkat:
      branch kitkat ( 1 commit, Sat Oct 4 22:55:31 2014 +0530):
             8dd591e7 DisplayDevice: Backwards compatibility with old EGL
    to gerrit.aicp-rom.com (y/N)? y
    The authenticity of host '[gerrit.aicp-rom.com]:29418 ([195.154.174.249]:29418)' can't be established.
    RSA key fingerprint is 8c:9c:82:a7:4e:4f:8c:c6:c3:21:3d:c0:38:5d:25:58.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '[gerrit.aicp-rom.com]:29418,[195.154.174.249]:29418' (RSA) to the list of known hosts.
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.

    Any thoughts?
    I added public key to gerrit.aicp-rom.com from id_rsa.pub file too.

    No idea. You registered on gerrit too, right?