Open main menu

Gerrit/Alternatives to git-review

< Gerrit

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 suite your workflow.

Contents

Set upEdit

Download the commit-msg hook script from https://gerrit.wikimedia.org/r/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 curlEdit

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 wgetEdit

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 browserEdit

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

Save it to "myrepo/.git/hooks/"

CommitEdit

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

Push for reviewEdit

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 alsoEdit