Converting from Mercurial to Git
Posted by Derek Jones on August 25, 2011
On the back of last week’s announcement of EllisLab’s change to Git, a number of people have asked for some assistance in migrating their Mercurial repositories. If you Google for “convert from Mercurial to Git” you will find a number of very good, concise tutorials on converting your repos from Mercurial to Git. So rather than completely rehash those, here are some simple steps applied to an example CodeIgniter repository followed by links to what we think are the most helpful resources for converting your repositories.
It should be stated that if you aren’t maintaining a fork with changes and then all you need to do is the following and you’re ready to go (requires git-flow):
$ git clone git@github.com:EllisLab/CodeIgniter.git
$ cd CodeIgniter
$ git flow init
The instructions below assume that I have a Mercurial CodeIgniter fork in my ~/Sites/repos directory named codeigniter-hg. Your locations will vary, but the process will be the same.
- Download the fast-export tool and extract it anywhere you like, I’m going with my ~/Sites/repos directory
- Navigate to my CodeIgniter fork
$ cd ~/Sites/repos
$ ls
codeigniter-hg fast-export-fab6d6f - Create my new Git repo
$ git init codeigniter
$ cd codeigniter - Run the fast-export tool
$ ../fast-export-fab6d6f/hg-fast-export.sh -r ../codeigniter-hg - Watch the changesets fly by!
master: Exporting simple delta revision 755/2499 with 0/9/0 added/changed/removed files
master: Exporting simple delta revision 756/2499 with 0/9/0 added/changed/removed files
master: Exporting simple delta revision 757/2499 with 0/2/0 added/changed/removed files
... - When it is finished, checkout the repo so you are on a branch
$ git checkout - Initialize the branch structure with git-flow
I’m accepting all of the defaults, and doing so leaves me in the “develop” branch.
$ git flow init - Now you can import this repo into your GitHub account, or add the official repo as a remote…
$ git remote add github git@github.com:EllisLab/CodeIgniter.git - ...and see what’s brewing!
$ git pull github develop
That’s all there is to it. For a more in-depth look at migration or of the git-flow branching model, please read the references below.
References
Converting from Mercurial to Git - Hivelogic
Easy switch from Mercurial to Git - Jérôme Renard
Why aren’t you using git-flow? - Jeff Kreeftmeijer
A short [video] introduction to Git Flow - Mark Derricutt
Set up Git - github:help
