Tools for working with Git at Mozilla
Shell Python
Latest commit c6f4b46 Mar 18, 2016 @amccreight amccreight update git-bz-moz
Failed to load latest commit information.
git-bz-moz @ d4f9c61 update git-bz-moz Mar 18, 2016
private Moving check-for-updates into "private" directory so that it doesn't … Nov 27, 2012
.gitmodules Use Mercurial trychooser extension instead of the bundled one Mar 30, 2015
LICENSE Adding LICENSE (CC0). May 30, 2013
README.markdown handle missing python2 gracefully Nov 18, 2015
git-branchname Adding git-branchname. Mar 4, 2012
git-bz Adding git-bz-moz. Jan 18, 2012
git-bzexport Add a wrapper for hg bzexport Apr 5, 2015
git-edit-files Don't try to edit deleted files with git-edit-files. Jun 27, 2013
git-fix-whitespace Adding git-fix-whitespace tool. Oct 11, 2012
git-new-workdir Adding license blurb to git-new-workdir. May 30, 2013
git-patch-to-hg-patch Merge pull request #42 from strugee/python-to-python2 Apr 20, 2015
git-push-to-hg fix typo in comment Nov 18, 2015
git-push-to-try Avoid pushing other heads to try Jun 12, 2015
git-push-to-trychooser Use Mercurial trychooser extension instead of the bundled one Mar 30, 2015
git-qapplied Some cleanup for qapplied/qparent Nov 7, 2013
git-qparent Some cleanup for qapplied/qparent Nov 7, 2013
git-qrebase Adding qrebase. Jun 12, 2012
git-remote-link Explicitly use Python 2 in the shebang Mar 28, 2015
git-root Adding git-root, which outputs the root of the current git repo. Jul 26, 2013
git-to-hg-commit Fix usage message in git-to-hg-commit. Oct 18, 2012
git-tracks Restore some additional behavior for git-tracks with other combinatio… Mar 5, 2015
hg-patch-to-git-patch Explicitly use Python 2 in the shebang Mar 28, 2015
pre-commit Adding more helpful trailing-whitespace error message to pre-commit h… Jul 1, 2012 Reworking git-patch-to-hg-patch so it doesn't wrap lines unnecessaril… Jun 20, 2012


Tools for working with Git at Mozilla.

In order to set this up, clone this repository somewhere, run the git submodule init and then git submodule update command, and add your clone to $PATH.

Some commands require python2. If using mozilla-build on windows, python2 might be missing, but python exists and is actually python 2 (check by running python -V). On such case, you can create a copy of python.exe as python2.exe at the same location - probably at <mozilla-build>/python/.

Many of these tools rely on a notion of your current branch's "upstream branch". For example, git push-to-try pushes to try all patches in your current branch that aren't upstream. See the git-tracks section below for details on how to change your upstream branch.


Push commits from git to bugzilla. For example, to push the two top commits in your repository, run

git bz attach -e HEAD^^..

(This will complain if your commits don't mention the same bug number in their summaries.)

If a commit's message starts with "FOLD", it will be folded into the previous commit before pushing to bugzilla.

(Actually, git-bz can do more than push commits from git to bugzilla. But I don't use it for anything else, so I'm not sure which of the other features work with


Usage: git bzexport [-t/--tip] PATH_TO_HG_REPO [GIT_REVS]

Push commits from git to bugzilla using the bzexport Mercurial extension from the Mozilla version control tools repo.

The bzexport extension has some advantages over bz attach - for example, if multiple Bugzilla reviewers match the reviewer name you specify, bzexport will let you choose between them using a menu - so some users may prefer it.

This command is implemented using git-push-to-hg, so see that command's documentation for more details on the argument syntax.


Create a new working directory based off an existing local git repository.


Gets the name of the current branch's upstream branch. With -d or --default, git-tracks outputs "origin/master" if there's no upstream branch.

You can set this with git branch --set-upstream CURRENT_BRANCH UPSTREAM_BRANCH. (Don't do git branch --set-upstream BRANCH; that won't work right!)

Many other tools in this package use git tracks -d as your branch's "upstream branch".


Find the hg commit corresponding to a git commit.


Usage: git push-to-hg [-t/--tip] PATH_TO_HG_REPO [GIT_REVS]

Push commits from git to a new qqueue in an hg repository. If GIT_REVS is omitted, push the commits $(git merge-base HEAD $(git-tracks))..HEAD (i.e. everything in the current branch that's not upstream).

If -t or --tip is specified, pull and update the hg repository to latest tip before pushing. Otherwise, update the hg repository to the revision atop which the git commits are based.


Usage: git push-to-try [-r/--rev REVISION_OR_RANGE] [-t/--tip] PATH_TO_HG_REPO TRYCHOOSER_PARAMS

Push the commits $(git merge-base HEAD $(git-tracks))..HEAD (i.e. everything in the current branch that's not upstream) to try, by way of the given hg repository.

If -r/--rev REVISION_OR_RANGE is supplied, then push those commits to try instead of $(git merge-base HEAD $(git-tracks))..HEAD. For example, if you are working on a feature branch that was branched off of master, and want to push everything on that branch to try, use --rev master..HEAD.

TRYCHOOSER_PARAMS should be, e.g. -b do -p all -u all -t none.


Usage: git push-to-trychooser [-t/--tip] PATH_TO_HG_REPO [GIT_REVS]

The same as git push-to-hg, but also runs the interactive trychooser command before pushing the commits to try from the given hg repository.

To use this, you must install the trychooser Mercurial extension from its repository. (There are some out-of-date versions of this extension floating around, so be sure to use this repository.)


Outputs the last common revision of the current branch and upstream. (This command is a synonym for git merge-base HEAD $(git-tracks).)


An alias for git rebase -i $(git qparent). This lets you interactively rebase your current branch without moving the commits to a new upstream base.


Open all the files modified in the specified rev range in your $EDITOR. (If no rev range is specified, open the files modified in your current checkout.)


Eliminate any trailing whitespace from your uncommitted changes.

Note that this will reset your index; that is, any changes you've git add'ed will need to be added again. But it won't (or at least, shouldn't!) erase any changes.


Like hg qapplied, output the commits in this branch which are not upstream.


Format a patch from git format-patch as an hg patch.


Output the name of the active git branch, but if there's no git repository below the cwd, output nothing. This is useful when you want to display the current branch name on the command line.

For example, I have in my ~/.bashrc:

function vcs-branchname() {
  git_branch=`git branchname`
  if [[ "$git_branch" != "" ]]; then
    echo " ($git_branch)"

PS1='\[\033[01;$PROMPT_COLOR\]\u@\h\[\033[00m\]:\[\033[01;$PROMPT_COLOR\]\w\[\033[00m\]$BRANCH_NAME\$ '

which makes my prompt look like

jlebar@hostname:~/current/path (name-of-git-branch)$


A pre-commit hook which checks for .orig files and trailing whitespace.

To install this hook, symlink it into your repository's .git/hooks directory (with the name pre-commit).