DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Shrink a Bloated Git Repository and Optimize Pack Files
  • TFVC to Git Migration: Step-by-Step Guide for Modern DevOps Teams
  • Developer Git Commit Hygiene
  • How To Create a Go CLI Tool That Converts Markdowns to PDF Files

Trending

  • LLM Agents and Getting Started with Them
  • A 5-Step SOC Guide That Meets RBI Expectations and Strengthens Security Operations
  • Genkit Middleware: Intercept, Extend, and Harden your Gen AI Pipelines
  • You Don't Get to Retrofit Trust: Why API Security Must Be Designed In, Not Bolted On
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Convert a Mercurial Repository to Git Using hg-fast-export

Convert a Mercurial Repository to Git Using hg-fast-export

If you need to move your Mercurial repositories over to Git, then you should know about this tool. Read on to find out how to make your conversion (and life) easier.

By 
Drew Harvey user avatar
Drew Harvey
·
Mar. 20, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
25.1K Views

Join the DZone community and get the full member experience.

Join For Free

For the longest time, on my personal and side projects, I leveraged Mercurial as a source control system. It worked great, and I was always happy with it; however, I recently came to the decision that I wanted to start using Git for my source control. I've been using Git a lot at my primary employment and found it would be faster, easier, and overall better for my personal and side project source control. As a result, I decided to switch from Mercurial to Git, and have put together this little tutorial on how to convert a Mercurial repository to Git using hg-fast-export.

To convert my Mercurial repositories to Git, I decided to take advantage of a utility called hg-fast-export.

NOTE: This assumes you already have Git installed on your environment. If you do not have Git installed, please visit https://git-scm.com/ to download and install the latest release of Git to your environment.

Step 1. Download hg-fast-export

To convert a Mercurial repository to Git, I recommend using a tool called hg-fast-export, which you'll need to use git to clone.

git clone git://repo.or.cz/fast-export.git
Step 2. Create a New Git Repository

The next step is to create and initialize a new empty Git repository.

mkdir new_git_repository
cd new_git_repository
git init
Step 3. (Optional) Configure core.ignoreCase

If you find hg-fast-export complaining about the option core.ignoreCase being set to true in the Git repository, risking possible empty changesets for renamed files, you can set the option core.ignoreCase in the Git repository to false to ensure that renamed files add to the changesets.

git config core.ignoreCase false
Step 4. Execute hg-fast-export

The next step is to run the hg-fast-export utility from the newly created and initialized Git repository folder, specifying the path to the Mercurial repository you wish to export and import it back into the Git repository.

/path/to/hg-fast-export.sh -r /path/to/hg_repo
Step 5. Checkout HEAD

The hg-fast-export utility does not automatically checkout the newly imported repository. You will need to follow up the import with a git checkout command to checkout the HEAD revision.

git checkout HEAD
Step 6. Push Git Repository Server-Side

To push the newly populated Git repository to a remote server, you'll need to add a remote origin location and execute a push to the remote origin/master branch.

git remote add origin git@my-git-server:my-repository.git
git push -u origin master
Step 7. Copy Over Untracked Files and Update .gitignore

Once this has been completed, you'll also need to copy over any untracked files from the Mercurial repository to the Git repository, and modify the .gitignore file to specifically ignore the untracked files. You'll then want to commit the .gitignore file to your local repository and push updates out to the remote server.

Git source control Repository (version control) Convert (command)

Published at DZone with permission of Drew Harvey. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Shrink a Bloated Git Repository and Optimize Pack Files
  • TFVC to Git Migration: Step-by-Step Guide for Modern DevOps Teams
  • Developer Git Commit Hygiene
  • How To Create a Go CLI Tool That Converts Markdowns to PDF Files

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook