Firefox Git Migration, the unofficial guide
The migration is imminent. By the time you read this, it has probably already happened.
The official procedure to migrate a developer's workstation is to create a fresh clone and manually transfer local branches through patch files.
That can be a bit limiting, so here I'm going to lay out an alternative (unofficial) path for the more adventurous who want to convert their working tree in-place.
The first step—if you don't already have it—is to install git-cinnabar
, because it will be used. Then jump to the section that applies to your setup.
Installing git-cinnabar
Run the following commands:
$ mkdir -p ~/.mozbuild/git-cinnabar
$ cd ~/.mozbuild/git-cinnabar
$ curl -sOL https://raw.githubusercontent.com/glandium/git-cinnabar/master/download.py
$ python3 download.py && rm download.py
$ PATH=$PATH:$HOME/.mozbuild/git-cinnabar
Migrating from Mercurial
This was covered in my previous post about the migration, but here is an up-to-date version:
As a preliminary to simplify the conversion, in your local clone of the Mercurial repository, apply your MQ stacks and create bookmarks for each of the heads in the repository.
Something like the following should list all your local heads:
$ hg log -r 'head() & draft()'
And for each of them, you can create a bookmark with:
$ hg bookmark local/<name> -r <revision>
(the local/
part is a namespace used to simplify the conversion below)
Then run the following commands:
$ git init
$ git remote add origin https://github.com/mozilla-firefox/firefox
$ git remote update origin
$ git -c cinnabar.graft=true fetch hg://hg.mozilla.org/mozilla-unified
$ git -c cinnabar.refs=bookmarks fetch hg::$PWD refs/heads/local/*:refs/heads/*
$ git reset $(git cinnabar hg2git $(hg log -r . -T '{node}'))
And you're all set. The local master
branch will point to the same commit your Mercurial repository was checked out at. If you had local uncommitted changes, they are also preserved. Once you've verified everything is in order and have converted everything you need, you can run the following commands:
$ rm -rf .hg
$ git cinnabar clear
Migrating from gecko-dev
If for some reason you have a gecko-dev clone that you never used with git-cinnabar, you first need to initialize git-cinnabar, running the following command in your working copy:
$ git -c cinnabar.graft=true fetch hg://hg.mozilla.org/mozilla-unified
Once the above ran, or if you already had used gecko-dev with git-cinnabar, you can processed with the conversion. Assuming the remote that points to https://github.com/mozilla/gecko-dev is origin
, run:
$ git remote set-url origin hg://hg.mozilla.org/mozilla-unified
Then, follow the instructions in the section below for migrating from a plain git-cinnabar clone.
Migrating from a plain git-cinnabar clone
Run the following command from your local working copy:
$ git -c cinnabar.graft=https://github.com/mozilla-firefox/firefox cinnabar reclone --rebase
That command will automatically rebase all your local branches on top of the new git repository.
If the reclone
command output something like the following:
Could not rewrite the following refs:
refs/heads/<name>
They may still be based on the old remote branches.
it means your local clone may have contained branches based on a different root, and the corresponding branches couldn't be converted. You'll have to go through them to rebase them manually.
Once everything is in order, you can finish the setup. Assuming the remote that points to the Mercurial repository is origin
, run:
$ git remote set-url origin https://github.com/mozilla-firefox/firefox
$ git -c fetch.prune=true remote update origin
$ git cinnabar clear
You may need to adjust the upstream branches your local branches track. Run git remote show -n origin
to check which remote branch each local branch is set to merge with. If you see entries like merges with remote branches/<something>
or merges with remote bookmarks/</something>
, you'll need to update your Git configuration accordingly. You can inspect those settings using the output of git config --get-regex 'branch.*.merge'
.
If you encounter any problem, please leave a comment below or ping @glandium
on #git-cinnabar on Element.
2025-04-30 18:07:40+0900