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
(version 0.7.0 or newer), because it will be temporarily used for the migration. Then jump to the section that applies to your setup.
Edit: But what section applies? You might ask.
If you're using Mercurial, you already know ;)
If you're using Git, the following commands will help you figure it out (assuming you already installed git-cinnabar, see below):
git cinnabar git2hg 05e5d33a570d48aed58b2d38f5dfc0a7870ff8d3
If the command prints out 9b2a99adc05e53cd4010de512f50118594756650
, you want the section for gecko-dev. If it prints 0000000000000000000000000000000000000000
, try the next command.
git cinnabar git2hg 028d2077b6267f634c161a8a68e2feeee0cfb663
If this command prints out 9b2a99adc05e53cd4010de512f50118594756650
, go to the section for a pure git-cinnabar clone. Otherwise, try the next command.
git cinnabar git2hg 2ca566cd74d5d0863ba7ef0529a4f88b2823eb43
If this command prints out 9b2a99adc05e53cd4010de512f50118594756650
, congratulations, you're already using the new repository. This can happen if you bootstrapped during roughly the second half of April. Go to the section for a recently bootstrapped clone for some extra cleanup.
If none of the commands above returned the expected output, I don't know what to tell you, unfortunately :(
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
That will remove both the Mercurial repository and the git-cinnabar metadata, leaving you with only a git repository.
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 by following the instructions in the section below for migrating from a recently bootstrapped clone.
Migrating from a recently bootstrapped clone
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
Once you've run that last command, the git-cinnabar metadata is gone, and you're left with a pure git repository, as if you had cloned from scratch (except for some now dangling git objects that will be cleaned up later by git gc
)
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
You can leave a response, or trackback from your own site.