User:Wctaiwan/Gerrit cheatsheet

Cloning an extensionEdit

git clone ssh://

Creating a new patchsetEdit

Creating a new branchEdit

git checkout -b branch_name

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

Committing changesEdit

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 gerritEdit

git review

Testing / updating an existing patchsetEdit

Downloading a patchset from gerritEdit

git review -d 31337

This downloads the contents of, puts them in a new branch, and switches to the branch.

Updating a patchsetEdit

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 masterEdit

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 gerritEdit

git review

General commandsEdit

Switching between branchesEdit

git checkout branch_name

Bringing a branch up to date with the remoteEdit

git pull

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

Note: This command does not work for downloading new versions of a gerrit patchset. For this use case, it's probably easiest to just run git review -d <number> where <number> is the gerrit change number to download the patchset to a new branch, and work on that instead. Note that if you have previously used git review -d to download a patchset and made changes to it, but have not uploaded the changes to gerrit, running the command again would destroy all local changes, so you should first use git checkout -b branch_name to copy the local changes to a new branch if you want to preserve them.

Viewing the status of a branchEdit

git status

Viewing the commit log for a branchEdit

git log

Press 'q' to back out of this view.

Dangerous commandsEdit

Discarding changes to a file since the last commitEdit

git checkout file_name

Discarding all changes since the last commitEdit

git reset --hard

Deleting a branchEdit

git branch -D branch_name

Setting up tab completion for git commandsEdit