hg-git Extension

  • Note: This extension is not distributed with Mercurial.

Maintainers

Kevin Bullock, Georges Racinet & Dan V. P. Christiansen

Discussion

https://groups.google.com/group/hg-git, https://mattermost.heptapod.net/heptapod/channels/hg-git and IRC

Repository

https://foss.heptapod.net/mercurial/hg-git

Old web page

https://hg-git.github.io/

Overview

This extension adds the ability to work on a Git repository from Mercurial. It also allows using a Git server as a collaboration point for a team with developers using both Git and Mercurial. At the same time, it can also be used to interact with a Mercurial repository using Git.

Commits and changesets are converted losslessly from one system to another, so you can push from a Mercurial repository and another Mercurial client can pull it and their changeset node ids will be identical - Mercurial data does not get lost in translation. It is intended that Mercurial users may wish to use this to collaborate even if no Git users are involved in the project, and it may even provide some advantages if you're using bookmarks (see below).

Installation

This plugin is entirely in Python - you do not need to have Git installed on your system. The only dependency is Dulwich Python library.

To install hg-git, for example in ~/.hgext directory.

hg clone https://foss.heptapod.net/mercurial/hg-git ~/.hgext/hg-git

Testing.

hg --config extensions.hggit=~/.hgext/hg-git/hggit version -v

There should be no errors, and hg-git version should be visible.

Configuration

Configure your .hgrc to enable the extension by adding following lines:

[extensions]
hggit = /path/to/hg-git/hggit

Commands

You can clone a Git repository as you would clone a mercurial repository, for example :

hg clone git+https://github.com/dulwich/dulwich

will clone the git mirror of the hg-git repository in a directory named 'hg-git.git'.

If you want to clone a repository via ssh, you can do so using a git+ssh:// protocol prefix :

hg clone git+ssh://git@github.com/dulwich/dulwich

This will also create a bookmark for each git branch, and add local tags default/<branch name> for each branch. This is similar to origin/<branch name> in Git.

When you pull from a Git repository in the [paths] section of hgrc, it will "fast-forward" the bookmarks if the branches haven't diverged. It will also create local tags as above.

When pushing to Git, the following happens:

Using hg-git to interact with a hg repository with git

Note:

This section is outdated (references to master branch and exportbranch config)

You can create a local .git repository like this:

Edit the .hg/hgrc (or your ~/.hgrc if you want to make this the default):

[git]
intree=1

Then do the following from in the hg repository:

hg gexport

This will create a .git repository in the working directory (alongside the .hg directory) that you can interact with like any regular git repository. If you have made commits in the git repository and want to convert them to hg commits, first make sure the changes you want are on the master branch, then do:

hg gimport

This will put your changes on top of the current hg tip.

Optionally you can change your hgrc to include an exportbranch statement:

[git]
intree=1
exportbranch=refs/heads/from-hg

This will cause 'hg gexport' to update the 'from-hg' branch, instead of the master branch, so that your changes will not be lost even if you work on the master branch.

TODO

TODO: this section is outdated

If you want to help with the development of hg-git, here are some things you can help with:

Alternatives

Git extension

The GitExtension, which is packaged with Mercurial, interacts with a Git repository directly, avoiding the intermediate conversion. This has certain advantages:

However, it is not able to handle all Git repositories; in particular, it cannot handle octopus merges, i.e. commits with more than two parents.

Convert

The ConvertExtension, packaged with Mercurial, has Git support.


CategoryExtensionsByOthers

HgGit (last edited 2021-03-02 16:45:54 by DanVilliomPodlaskiChristiansen)