First you have to register a user account at (requires an openid) and add your ssh public key.


Configure in your ~/.ssh/config:

Port 29418
User <gerritusername>

Either checkout a new tree:

git clone -o gerrit

(If you didn't configure .ssh/config use git clone -o gerrit ssh://<gerritusername>

or add the remote to your existing checkout:

git remote add gerrit

Also you want the commit-msg hook, you can get it with (in the checkout directory):

scp .git/hooks/
chmod +x .git/hooks/commit-msg

(If you didn't configure .ssh/config use this to copy it: scp -p -P 29418 <gerritusername> .git/hooks/)

To push changes ("pull requests" in github language) to gerrit you want to push to "refs/for/master" (all work is currently done on the master branch). I like to use the following to always push to this ref:

git config --add remote.gerrit.push HEAD:refs/for/master

If you want to download all changes on git remote update you can add this too:

git config --add remote.gerrit.fetch '+refs/changes/*:refs/remotes/gerrit/changes/*'

Uploading a change ("pull request")

Just create your commits as usual. As the review is done per commit you should make sure each commit compiles and is a fine change on its own. Use git rebase to squash, edit and reorder your commits (git rebase is the most powerful tool for advanced git users).

Then just push it to gerrit refs/for/master, if you configured it like above this should work fine:

git push gerrit

(Or make it explicit: git push gerrit HEAD:refs/for/master)

Depending on the feedback of the review you can then change your commits (git rebase or for single commits git commit --amend) and upload them again. The "commit-msg" hook you installed will have added a Change-Id to each commit which is used to track changes. (If you didn't use the hook, gerrit adds its own id; you need to pull the commit from gerrit in this case to modify it.)

Updated by stbuehler over 3 years ago · 3 revisions