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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

Related

  • Developer Git Commit Hygiene
  • How To Create a Go CLI Tool That Converts Markdowns to PDF Files
  • A Comprehensive Guide to GitHub
  • Mastering Git

Trending

  • Build an Advanced RAG App: Query Rewriting
  • Next-Gen Lie Detector: Stack Selection
  • Outsmarting Cyber Threats: How Large Language Models Can Revolutionize Email Security
  • Tenv v2.0: The Importance of Explicit Behavior for Version Manager
  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
Like (2)
Save
Tweet
Share
23.7K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Developer Git Commit Hygiene
  • How To Create a Go CLI Tool That Converts Markdowns to PDF Files
  • A Comprehensive Guide to GitHub
  • Mastering Git

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: