Hello, guest. Welcome!

News and thoughts from the people at EllisLab.

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.

  1. Download the fast-export tool and extract it anywhere you like, I’m going with my ~/Sites/repos directory
  2. Navigate to my CodeIgniter fork
    cd ~/Sites/repos
    ls
    codeigniter
    -hg    fast-export-fab6d6f 
  3. Create my new Git repo
    git init codeigniter
    cd codeigniter 
  4. Run the fast-export tool
    $ ../fast-export-fab6d6f/hg-fast-export.sh -../codeigniter-hg 
  5. Watch the changesets fly by!
    masterExporting 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
    ... 
  6. When it is finished, checkout the repo so you are on a branch
    git checkout 
  7. Initialize the branch structure with git-flow
    git flow init 
    I’m accepting all of the defaults, and doing so leaves me in the “develop” branch.
  8. 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 
  9. ...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

Comments

blog comments powered by Disqus
EllisLab Products and Services

Copyright 2002-2012 · EllisLab, Inc. · All rights Reserved

Powered by ExpressionEngine, of course!