User:Wctaiwan/Gerrit cheatsheet

Cloning an extension
git clone ssh://username@gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage.git

Creating a new branch
git checkout -b branch_name

This creates a branch called  and switches to it. Note that this can be done at any point before you commit (i.e. if you accidentally make changes on the master branch, just run  and commit on that).

Committing changes
git add. git commit

This adds all changed files to the staging area and commits the changes. You can also specify file names in place of  to commit specific changed files.

Uploading the patchset to gerrit
git review

Downloading a patchset from gerrit
git review -d 31337

This downloads the contents of https://gerrit.wikimedia.org/r/31337/, puts them in a new branch, and switches to the branch.

Updating a patchset
git add. git commit --amend

This amends the latest commit (i.e. the one containing the patchset) to include all of the changes you have made.

Rebasing a patchset on master
First, try clicking "Rebase" in gerrit. If that fails, make sure everything is committed, and then run git checkout master git pull git checkout branch_name git rebase master

Follow the on-screen instructions.

Uploading the updated patchset to gerrit
git review

Switching between branches
git checkout branch_name

Bringing a branch up to date with the remote
git pull

In general, it's a good idea to run  before making changes so that you're always working on top of the latest copy.

Note that this command does not work if you created the branch yourself for a new patchset, and someone else uploaded an updated version. In that case, it's probably easiest to just run  where is the gerrit change number and work on that branch instead.

Viewing the status of a branch
git status

Viewing the commit log for a branch
git log

Press 'q' to back out of this view.

Deleting a branch
git branch -D branch_name

Setting up tab completion for git commands
http://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks#Auto-Completion