Hg-Git Mercurial Plugin
We hear from a number of people who are using Mercurial for their projects but want to host them on GitHub because they want their project to benefit from the…
We hear from a number of people who are using Mercurial for their projects but want to host them on GitHub because they want their project to benefit from the community here. Or perhaps they are in a group where some of the developers want to use Mercurial and others want to use Git and so they just stick with Subversion (ugh). We don’t want to live in a world where developers who are ready to switch to a DVCS end up staying with Subversion.
So, I’ve been working on a plugin for Mercurial that lets it communicate with a Git server as a native Git client. I give you hg-git!
This means that if you are a Mercurial developer you can install this plugin and then push and pull to and from Git servers, either GitHub or somewhere else. It is a lossless bi-directional bridge, meaning you can push to a Git server from one Hg user, then another Hg user can clone using this plugin and the node ids will all be identical. It can even handle things like tags, explicit renames, named branches, octopus merges and more.
The plugin is pretty far along at this point – I’ve been using it for all the hg-git development and I’ve heard from a number of others who are using it successfully even on relatively large projects. It is slow sometimes and may not handle some edge cases well, but the software is rapidly maturing. If you do use it, please let me know about any issues you run into, we want to make this rock solid.
There are no external dependencies – the library is entirely written in python and contains a pure python implementation of all the Git functionality it needs, so you don’t need to have Git installed locally at all. It has been known to work with Mercurial 1.1 and 1.2 – let me know if you try it with something else.
Usage
From Hg with the plugin installed, you can clone a Git repository like this:
$ hg clone git://github.com/schacon/munger.git
Or, if you have an existing Hg repository, you can run something like this:
$ cd myproject # (an Hg repository)
$ hg gremote add origin git(at)github.com:schacon/myproject.git
$ hg gpush
With those two commands you can basically import your Hg repository into a GitHub repository. Then people can fork and work on your code in Hg or in Git and push back up, then you can pull in any contributed work with something like this:
$ hg gremote add scott git://github.com/scott/project.git
$ hg gfetch scott
$ hg update
The basic commands the plugin adds to the Hg command library are ‘gclone’, ‘gremote’, ‘gpush’ and ‘gfetch’ – all roughly equivalent to their Git counterparts. Also, running a normal ‘hg clone’ with an identifiable Git protocol (git://, git+ssh://) will fire up ‘gclone’ automatically.
See the hg-git homepage for more information.
Written by
Related posts
![](https://github.blog/wp-content/uploads/2023/10/Collaboration-DarkMode-2.png?resize=400%2C212)
2024 is the biggest global election year in history. What’s at stake for developers?
GitHub is considering what is at stake for our users and platform, how we can take responsible action to support free and fair elections, and how developers contribute to resilient democratic processes.
![](https://github.blog/wp-content/uploads/2023/10/AI-DarkMode-2.png?resize=400%2C212)
GitHub named a Leader in the Gartner first-ever Magic Quadrant for AI Code Assistants
This year, as part of its annual Magic Quadrant series, Gartner published a first-of-its-kind report analyzing the state of play in the AI Code Assistants market–and named GitHub a Leader.
![AI in software development 2024 survey results with colorful graphics and percentages.](https://github.blog/wp-content/uploads/2024/08/ai-survey-header.png?resize=400%2C212)
Survey: The AI wave continues to grow on software development teams
We surveyed 2,000 people on software development teams at enterprises in the U.S., Brazil, India, and Germany about the use, experience, and expectations around generative AI tools in software development.