4 **git-gerrit** is command line tool for the [Gerrit code review system][1], with an
5 emphasis on the Gerrit legacy numerical identifiers. The heavy lifting is done
6 with the **pygerrit2** package to access the Gerrit REST API.
7 **git-gerrit** is compatible with Python 2 and Python 3.
11 git gerrit-help List commands.
12 git gerrit-query Search gerrit.
13 git gerrit-fetch Fetch by gerrit number.
14 git gerrit-checkout Fetch then checkout by gerrit number.
15 git gerrit-log Show oneline log with gerrit numbers.
16 git gerrit-unpicked Find gerrit numbers on upstream branch not cherry picked.
17 git gerrit-cherry-pick Cherry pick from upstream branch by gerrit number.
18 git gerrit-install-hooks Install git hooks to create gerrit change-ids.
25 $ pip install --user git-gerrit
27 To install from source, clone the git repo and install with the provided
28 makefile. `make` will run `pip` to install the package and
31 $ git clone https://github.com/meffie/git-gerrit.git
35 Clone the git project under gerrit review, and in that project directory
36 set the Gerrit host and project names in the local git configuration::
38 $ cd <your-gerrit-project>
39 $ git config gerrit.host <gerrit-hostname>
40 $ git config gerrit.project <gerrit-project>
42 Finally, download the git hook provided by gerrit and a git hook provided
45 $ git gerrit-install-hooks
50 Setup a local OpenAFS git repo::
52 $ git clone git://git.openafs.org/openeafs.git # (if not already cloned)
54 $ git config --local gerrit.host gerrit.openafs.org
55 $ git config --local gerrit.project openafs
56 $ git gerrit-install-hooks
58 Find open gerrits on the master branch::
60 $ git gerrit-query -n3 is:open branch:master
61 13030 redhat: Make separate debuginfo for kmods work with recent rpm
62 13031 redhat: PACKAGE_VERSION macro no longer exists
63 13021 autoconf: update curses.m4
65 Find gerrits with subjects containing the term 'debuginfo'::
67 $ git gerrit-query -n3 debuginfo
68 13030 redhat: Make separate debuginfo for kmods work with recent rpm
69 13029 redhat: Create unique debuginfo packages for kmods
70 12818 redhat: separate debuginfo package for kmod rpm
72 Also show the branch name::
74 $ git gerrit-query -n3 --format='{branch:>20s} {_number} {subject}' debuginfo
75 master 13030 redhat: Make separate debuginfo for kmods work with recent rpm
76 openafs-stable-1_6_x 13029 redhat: Create unique debuginfo packages for kmods
77 openafs-stable-1_6_x 12818 redhat: separate debuginfo package for kmod rpm
79 List the gerrit topics on a branch::
81 $ git gerrit-query --format='{topic}' status:open branch:master | sort -u | head -n3
86 Show gerrit submissions on the master branch I need to review::
88 $ git gerrit-query branch:master status:open NOT label:Code-Review=-2 NOT reviewer:tycobb@yoyodyne.com
91 Fetch a gerrit by number::
93 $ git gerrit-fetch 12977
95 Checkout a gerrit by number::
97 $ git gerrit-checkout 13000
99 Cherry-pick a gerrit onto the current branch::
101 $ git gerrit-fetch --no-branch 13001 && git cherry-pick FETCH_HEAD
103 Show gerrit numbers in one the checked out branch::
106 12958 f47cb2d Suppress statement not reached warnings under Solaris Studio
107 12957 306f0f3 afs: squash empty declaration warning
108 12955 e006609 libafs: git ignore build artifacts on Solaris
110 Show gerrit numbers by a revision::
112 $ git gerrit-log -n3 openafs-stable-1_8_0
113 12953 a08327f Update NEWS for 1.8.0 final release
114 12938 acb0e84 afs_pioctl: avoid -Wpointer-sign
115 12950 b73863b LINUX: fix RedHat 7.5 ENOTDIR issues
117 Show gerrit numbers by a range of revisions::
119 $ git gerrit-log 607eba34d..origin/openafs-stable-1_8_x
120 13268 554176bd2 LINUX: Update to Linux struct iattr->ia_ctime to timespec64 with 4.18
121 13266 eb107ed5c Make OpenAFS 1.8.1
122 13265 8de978420 Update NEWS for 1.8.1
124 Show just the gerrit numbers and subjects::
126 $ git gerrit-log -n3 --format='{number}: {subject}'
127 12958: Suppress statement not reached warnings under Solaris Studio
128 12957: afs: squash empty declaration warning
129 12955: libafs: git ignore build artifacts on Solaris
131 Show the commits on the master branch which have not been cherry-picked on to
132 the stable branch. (Gerrits may already exists for them.)::
134 $ git gerrit-unpicked -u origin/master origin/openafs-stable-1_8_x
135 13656 4eeed830fa31b7b8b5487ba619acbc8d30642aaa afscp: Link against opr/roken/hcrypto
136 13659 f5f59cd8d336b153e2b762bb7afd16e6ab1b1ee2 util: serverLog using memory after free
137 13665 1210a8d6d96db2d84595d35ef81ec5d176de05e8 LINUX: Run the 'sparse' checker if available
144 Commonly used queries can be saved as git aliases. For example to show the
145 gerrits which have not been reviewed yet::
148 # git gerrit-todo [<branch>] [<userid>]
149 gerrit-todo = "!f() { git-gerrit-query \"branch:${1-master} is:open NOT label:Code-Review>=+1,${2-$USER}\"; }; f"
154 Command git-gerrit-checkout::
156 usage: git-gerrit-checkout [-h] [--repodir REPODIR] <number>
158 Fetch then checkout by gerrit number.
160 positional arguments:
161 <number> legacy change number
164 -h, --help show this help message and exit
165 --repodir REPODIR path to the git project directory
167 Command git-gerrit-cherry-pick::
169 usage: git-gerrit-cherry-pick [-h] [-b <branch>] <number>
171 Cherry pick from upstream branch by gerrit number.
173 positional arguments:
174 <number> legacy change number
177 -h, --help show this help message and exit
178 -b <branch>, --branch <branch>
179 upstream branch (default: origin/master)
181 Note: A new gerrit Change-Id will be created in the cherry-picked commit.
185 $ git gerrit-query is:merged branch:master 'fix the frobinator'
186 1234 fix the frobinator
189 $ git checkout -b fix origin/the-stable-branch
192 $ git gerrit-cherry-pick 1234 -b origin/master
193 [fix f378563c94] fix the frobinator
194 Date: Fri Apr 4 10:27:10 2014 -0400
195 2 files changed, 37 insertions(+), 12 deletions(-)
197 $ git push gerrit HEAD:refs/for/the-stable-branch
200 Command git-gerrit-fetch::
202 usage: git-gerrit-fetch [-h] [--repodir REPODIR] [--checkout] [--no-branch]
205 Fetch by gerrit number.
207 positional arguments:
208 <number> legacy change number
211 -h, --help show this help message and exit
212 --repodir REPODIR path to the git project directory
213 --checkout checkout after fetch
214 --no-branch do not create a local branch
216 Command git-gerrit-help::
219 Commands for gerrit code review:
221 git gerrit-help List commands.
222 git gerrit-query Search gerrit.
223 git gerrit-fetch Fetch by gerrit number.
224 git gerrit-checkout Fetch then checkout by gerrit number.
225 git gerrit-log Show oneline log with gerrit numbers.
226 git gerrit-unpicked Find gerrit numbers on upstream branch not cherry picked.
227 git gerrit-cherry-pick Cherry pick from upstream branch by gerrit number.
228 git gerrit-install-hooks Install git hooks to create gerrit change-ids.
230 Show command details with:
232 git gerrit-<command> -h
234 Command git-gerrit-install-hooks::
236 usage: git-gerrit-install-hooks [-h]
238 Install git hooks to create gerrit change-ids.
241 -h, --help show this help message and exit
243 Command git-gerrit-log::
245 usage: git-gerrit-log [-h] [--repodir REPODIR] [--format FORMAT] [-n NUMBER]
249 Show oneline log with gerrit numbers.
251 positional arguments:
252 revision revision range
255 -h, --help show this help message and exit
256 --repodir REPODIR path to the git project directory
257 --format FORMAT output format (default: "{number} {hash} {subject}")
258 -n NUMBER, --number NUMBER
260 -r, --reverse reverse order
261 -l, --long-hash show full sha1 hash
263 format fields: number, hash, subject
265 Command git-gerrit-query::
267 usage: git-gerrit-query [-h] [--repodir REPODIR] [-n LIMIT] [--format FORMAT]
273 positional arguments:
277 -h, --help show this help message and exit
278 --repodir REPODIR path to the git project directory
279 -n LIMIT, --number LIMIT
280 limit the number of results
281 --format FORMAT output format string
283 --details get extra details
285 Command git-gerrit-unpicked::
287 usage: git-gerrit-unpicked [-h] [-u UPSTREAM_BRANCH] downstream_branch
289 Find gerrit numbers on upstream branch not cherry picked.
291 positional arguments:
292 downstream_branch downstream branch name
295 -h, --help show this help message and exit
296 -u UPSTREAM_BRANCH, --upstream-branch UPSTREAM_BRANCH
304 See the [git-review][2] project for a more complete git/gerrit workflow tool.
307 [1]: https://www.gerritcodereview.com/
308 [2]: https://www.mediawiki.org/wiki/Gerrit/git-review