DEV Community

Mike Roberts
Mike Roberts

Posted on

Hg to Git with no hassles

I got you.

Easy conversion

Step 1: Import your repository to Github

If you're happy to switch to Github, congrats, you're done.

Step 2: Import your newly converted repo into Bitbucket

When you've done this, all of your existing author records will be the same as they were before. This is warts and all. One upside to using frej/fast-export is the opportunity to clean things up a little bit.

Gotchas

  • Github won't keep your closed branches around. For some this will be a blessing. Others not so much.
  • If you import to Github and stop there you may need to do some manual work to attribute your repo authors to Github users. You can do this at any time though and it's simple to do. Here's the docs.
  • There is no bulk UI import tool - this is one at a time, baby.
  • If you use 2FA on Github you may need to generate a personal access token in place of your Github password.
  • But what about comments on commits in Bitbucket / pull requests? They won't travel with you but Rarified has got you covered. See their scripts here to backup metadata from Bitbucket.
  • Disclaimer: Every repository has a history and some will be cleaner than others. As such your mileage with this method may vary. I do recommend trialling both and deciding which is best for you.

Good luck and let me know how you go!
Mike

Top comments (2)

Collapse
 
syntaxseed profile image
SyntaxSeed (Sherri W)

Wait... GitHub can import an Hg repo & convert it to Git for you?? Why did I not notice this?
🤦‍♀️

I think because I was originally migrating to GitLab & they didn't have that option. Now I'm switching to GitHub & everything is Git now anyway. Just 1 lone Hg repo left... Lol

Collapse
 
zer0pants profile image
Mike Roberts

Totally! It was literally the last thing I found / tried as I started with the official git docs first and then tried various methods to proof what would be best for us. Almost missed it entirely.

On Friday I thought I'd give it a try and it worked a treat. My motivation was, "If I have to get help to finish migrating 60+ repos how could I do it?". Almost anyone can do the above but you've got to know quite a bit more to use the other methods.