Gerrit/Alternatives to git-review

If installing git-review is not feasible for you, you can use plain Git as well. This can sometimes be a better option if git-review doesn't suit your workflow.

Set up

Download the commit-msg hook script from gerrit:tools/hooks/commit-msg and save it in the .git/hooks/ subdirectory of your cloned copy of the repository. There's three ways to do it:

Using curl

cd myrepo/
curl https://gerrit.wikimedia.org/r/tools/hooks/commit-msg > .git/hooks/commit-msg

Mark the file as as "executable". In Linux you can change this with:

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

Using wget

cd myrepo/
wget -P .git/hooks https://gerrit.wikimedia.org/r/tools/hooks/commit-msg

Mark the file as as "executable". In Linux you can change this with:

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

Using the web browser

Select "Save as..." from the context menu when right-clicking on this link: gerrit:tools/hooks/commit-msg

Save it to myrepo/.git/hooks/

Commit

Whenever you commit a change locally, the hook script will automatically add a unique "Change-Id" to the commit message.

Push for review

Add to following Git alias to simplify the command to push changes to Gerrit for review. You can do this by executing the following:

 git config --global alias.push-for-review "push gerrit HEAD:refs/for/master"

If you have a single 'origin' remote, then in the above command replace 'gerrit' with 'origin':

 git config --global alias.push-for-review "push origin HEAD:refs/for/master"

The refs/for/ part is a virtual branch prefix used by Gerrit. However, you may replace "master" with another remote branch that you want to commit to. E.g.: When trying to push to the remote branch Foo use refs/for/Foo.

Push a commit to Gerrit with:

 git push-for-review

If you want to group a few related changesets (when working on a feature, or just to make them searchable in Gerrit), you can push them under the same topic using refs/for/Foo/topic, for example:

git push gerrit HEAD:refs/for/master/T12345

git push gerrit HEAD:refs/for/master/my-feature

See also