Skip to content

Instantly share code, notes, and snippets.

@joechrysler
Created May 2, 2012 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joechrysler/2580265 to your computer and use it in GitHub Desktop.
Save joechrysler/2580265 to your computer and use it in GitHub Desktop.
Pushing mercurial repositories to github

Pushing mercurial into github

a guide for sceptic's

It's easy they said. Distributed SCMs are all basically the same they said, so transitioning from one to the other is super easy. So easy that in the time it's taken to write this sentence, you should have already installed a plugin and pushed your mercurial repo up to github right?

Lies. Horrible horrible lies.

The mercurial to git conversion is nothing short of a pain. Documentation is spotty and full of that peculiarly glib variety of optimism found most often at fast food eateries and VC-funded startups. But you know that already. That's why you're here after all.

Is all lost?

no. you can escape the plastic land of hg and enter the land of gritty git goodness.

But how, cried the traveller

It isn't simple, but it is pretty easy. First, just so we're all on the same page here, you'll need an hg repo and an empty github repo. You'll also need to install the hg-git extension to mercurial. Don't worry, it's super easy.

Right, I have the repos, now what?

First, fire up a terminal and cd into your hg repo. You shouldn't need to cd anywhere else, so bring a sandwich. We'll be here for a minute or two. After you've had your snack, load up .hg/hgrc and make sure it has something like this tucked neatly inside:

[paths]
origin = git+ssh://git@github.com/joechrysler/repo.git

Back to the terminal now, run hg branches | sed 's/\(\w*\).*:\(\w*\).*/\2 \1/' >> .hg/bookmarks to add a bookmark for every branch in hg (not just master). You might also want to open up .hg/bookmarks in an editor and change default to master to better fit the git idiom. For this step you'll need to have turned on the hg bookmarks extension.

Almost there now. From now we need to clean up any git nonsense that might be sitting around with hg gc. Push it up to github with hg push origin, and you're done! You're processor and nic, however, will be chugging on the commits for a while, so it's probably a good time to grab another of those sandwiches.

D-O-N-E

you now have a full copy of your hg repository on github!

@HerrPi
Copy link

HerrPi commented Feb 8, 2020

I also had lots of pain the hg-git extension way. But I definitely succeeded the fast-export Python tool way. If you or anyone is interested, have a look:
https://gist.github.com/HerrPi/5ad9a2cd68163483fc3e23801caa5086

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