Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mariomarin/3434893 to your computer and use it in GitHub Desktop.

Select an option

Save mariomarin/3434893 to your computer and use it in GitHub Desktop.
I prefer to work in Git and push changes out to Hg

Updated version of the instructions in http://traviscline.com/blog/2010/04/27/using-hg-git-to-work-in-git-and-push-to-hg/ with a few tweaks

  1. Install hg-git (e.g. pip install hg-git)

  2. Make sure you've enabled the Hg bookmark extension in your .hgrc

  3. Add this to your .hgrc:

    [git]
    intree=1
    [extensions]
    hggit =
    

And also .hg/hgignore: http://mercurial.selenic.com/wiki/TipsAndTricks#Ignore_files_in_local_working_copy_only

  1. Clone your Mercurial repo:

    $ hg clone https://[email protected]/ned/coveragepy
    
  2. Change into the repo:

    $ cd coveragepy
    
  3. Create a local bookmark tracking your Mercurial default branch - this is what will be exported to Git:

    $ hg bookmark hg/default -r default
    
  4. Export to the git repo:

    $ hg gexport
    
  5. Configure Hg to ignore the Git repo:

    $ echo ".git" >> .hg/hgignore
    
  6. Configure Git to ignore the Hg repo:

    $ echo ".hg*" >> .git/info/exclude
    
  7. Configure Git to ignore the same things as Mercurial:

    $ git config core.excludesfile `pwd`/.hg/hgignore
    
  8. Have your master branch track the exported Hg default branch:

    $ git branch --track hg/default master
    $ git reset --hard
    
  9. hg-git created a "bare" git repository, even with intree = 1. Change that in .git/config, replace bare = true by bare = false.

  10. Do stuff in Git and make commits

  11. Export your changes to Hg:

    $ hg gimport
    
  12. Push them out to the world:

    $ hg push
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment