How to work in Git and push changes to Mercurial using hg-git

I often need to work with both Git and Mercurial repositories. I've previously used hg-git to work in Hg and push changes to Git but have found Mercurial to be less comfortable than Git (no flames, please: this is the newer vi-Emacs debate. Use the one you like) and was hoping to work in the opposite manner: local changes in Git pushed to an Hg repo on BitBucket or Google Code.

Travis Cline posted some instructions for working in Git and pushing changes to Hg which I've updated with a few stylistic tweaks:

  • Install hg-git (e.g. ``pip install hg-git``)
  • Make sure you've enabled the Hg bookmark extension in your ``.hgrc``
  • Add this to your .hgrc::
    
        [git]
    
        intree=1
    
    
  • Clone your Mercurial repo::
    
        $ hg clone https://acdha@bitbucket.org/ned/coveragepy
    
    
  • Change into the repo::
    
        $ cd coveragepy
    
    
  • Create a local bookmark tracking your Mercurial default branch - this is what will be exported to Git::
    
    
    
        $ hg bookmark hg/default -r default
    
    
  • Export to the git repo::
    
        $ hg gexport
    
    
  • Configure Hg to ignore the Git repo::
    
        $ echo ".git" >> .hg/hgignore
    
    
  • Configure Git to ignore the Hg repo::
    
        $ echo ".hg*" >> .git/info/exclude
    
    
  • Configure Git to ignore the same things as Mercurial::
    
        $ git config core.excludesfile `pwd`/.hg/hgignore
    
    
  • Have your master branch track the exported Hg default branch::
    
        $ git branch --track hg/default master
    
        $ git reset --hard
    
    
  • Do stuff in Git and make commits
  • Export your changes to Hg::
    
        $ hg gimport
    
    
    
    
  • Push them out to the world::
    
        $ hg push
    
    
comments powered by Disqus