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
Please enter at least three characters to search
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

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

  • A Simple, Convenience Package for the Azure Cosmos DB Go SDK
  • Secrets Sprawl and AI: Why Your Non-Human Identities Need Attention Before You Deploy That LLM
  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  • Cosmos DB Disaster Recovery: Multi-Region Write Pitfalls and How to Evade Them
  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
24.4K 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
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and 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:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!