Using hggit with existing Mercurial projects

I want to use hggit. Not because I like git, but because Xcode 4 uses git. So I need a two way bridge between hg and git, which hggit provides.

1. Install dulwich:

sudo easy_install dulwich

Have multiple Pythons installed? Make sure you use correct easy_install, for example:

sudo /usr/bin/easy_install2.6 dulwich

2. Get hggit, either with git or hg (guess which one I prefer):

hg clone hggit

3. Edit your ~/.hgrc; add the hggit and bookmarks extensions:

. . .

4. In your Mercurial repository, punch this in:

hg bookmark master -r default
hg gexport

and voilà! You have a .git repository.

5. To pull git changesets (commits) back into hg, it should require just:

hg gimport

I didn’t yet get here.

Xcode 4 simply refuses to work with git repositories created from Mercurial. It recognizes the branches, but not the log itself. No idea why yet. Ah well. 🙂

Update: Xcode 4 is sensitive to repositories being “bare”, whatever that means for Git. (Apparently that is a locally created, non-cloned Git repository without a “remote”.) Edit .git/config, and change “bare = true” to “bare = false”. This allows you to see the history.

But don’t do that. There appear to be other incompatibilities that I could not fix. For example, all files are marked as “D-eleted”. Also, setting bare to false will make the following steps fail. So what you really want to do is:

cd ..
git clone MyProject MyProjectGIT
# now mess with the project in MyProjectGIT
git commit -m "Whatever"
git push
cd ..
cd MyProject
hg gimport

(First few commands are run through Xcode 4 GUI, of course.)

Don’t forget that your git username and email is unconfigured. (Absurdly, I could not find GUI in Xcode 4 to edit this!) Terminal back to the rescue again.

git config --global "Your Name"
git config --global


2 thoughts on “Using hggit with existing Mercurial projects

  1. Murray Todd Williams

    Thanks for putting this page out. My (horribly organized and barely standardized) workgroup uses Mercurial (one guy uses Git), I've got a dozen project on different platforms (ActionScript 3 / Flex, Java with or without Maven, etc.) and a new Xcode initiative is starting up. I just watched the WWDC 2011 session on revision control that showed cool Git functionality, and I guess HG is just not in the picture right now.

    I am curious: have you had a chance to really "kick the tires" in this implementation since this blog entry posting date (May 23rd)? Is it working well for you? Does it seem robust for heavy use?


    1. Ivan Vučica Post author

      I like to think I have used it sufficiently to state that it is stable, but horribly awkward to use.

      Coming from svn, and having invested time in hg, I find git extremely awkward and complex to use. Git is surely a lot more powerful, but it operates with a different set of values. It is more of a patch merge system than a version control system – and that is only to be expected, considering Torvalds' use case. Git deals with hunks, hg deals with files.

      Simple operations such as "hg rollback" in case of an incorrect commit message or incomplete commit are hard with git. I also find it easier to deal with local revision numbers as aliases.

      Regarding Xcode's VCS functionality… Uhm. The only notable things are:
      – diff
      – automatic rename when file is renamed in IDE
      – automatic addition when file is added in IDE

      It is buggy, and of limited use. It does not seem to have a nice merge functionality. I did not even find a revert functionality.

      If I were you, I would stick to manual version control through command line with either Hg or Git, or using something like SourceTree (supports Hg and Git, currently free on Mac App Store). Unless git support in 4.2 was significantly improved, don't introduce it in the workflow.


Leave a Reply

Your email address will not be published.


What is 9 + 6 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

This site uses Akismet to reduce spam. Learn how your comment data is processed.