Skip to main content

push to and pull from a Git repository using Mercurial

Project description

Hg-Git Mercurial Plugin

Homepage:

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

Repository:

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

Mailing list:

hg-git@googlegroups.com (Google Group)

This is the Hg-Git plugin for Mercurial, adding the ability to push and pull to/from a Git server repository from Hg. This means you can collaborate on Git based projects from Hg, or use a Git server as a collaboration point for a team with developers using both Git and Hg.

The Hg-Git plugin can convert commits/changesets losslessly from one system to another, so you can push via a Mercurial repository and another Hg client can pull it and their changeset node ids will be identical - Mercurial data does not get lost in translation. It is intended that Hg 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).

Dependencies

This plugin is implemented entirely in Python — there are no Git binary dependencies, and you do not need to have Git installed on your system. The only dependencies are:

  • Mercurial 5.4

  • Dulwich 0.19.3

  • Python 3.8

Please note that these are the earliest versions known to work; later versions generally work better.

Installing

We recommend installing the plugin using your a package manager, such as pip:

python -m pip install hg-git

Alternatively, you can clone this repository somewhere and install it from the directory:

hg clone https://foss.heptapod.net/mercurial/hg-git/
cd hg-git
python -m pip install .

And enable it from somewhere in your $PYTHONPATH:

[extensions]
hggit =

Contributing

The primary development location for Hg-Git is Heptapod, and you can follow their guide on how to contribute patches.

Alternatively, you can follow the guide on how to contribute to Mercurial itself, and send patches to the list.

Usage

You can clone a Git repository from Mercurial by running hg clone <url> [dest]. For example, if you were to run:

$ hg clone git://github.com/hg-git/hg-git.git

Hg-Git would clone the repository and convert it to a Mercurial repository for you. Other protocols are also supported, see hg help git for details.

If you are starting from an existing Mercurial repository, you have to set up a Git repository somewhere that you have push access to, add a path entry for it in your .hg/hgrc file, and then run hg push [name] from within your repository. For example:

$ cd hg-git # (a Mercurial repository)
$ # edit .hg/hgrc and add the target git url in the paths section
$ hg push

This will convert all your Mercurial data into Git objects and push them to the Git server.

Now that you have a Mercurial repository that can push/pull to/from a Git repository, you can fetch updates with hg pull:

$ hg pull

That will pull down any commits that have been pushed to the server in the meantime and give you a new head that you can merge in.

Hg-Git pushes your bookmarks up to the Git server as branches and will pull Git branches down and set them up as bookmarks.

Hg-Git can also be used to convert a Mercurial repository to Git. You can use a local repository or a remote repository accessed via SSH, HTTP or HTTPS. Use the following commands to convert the repository, it assumes you’re running this in $HOME:

$ mkdir git-repo; cd git-repo; git init; cd ..
$ cd hg-repo
$ hg bookmarks hg
$ hg push ../git-repo

The hg bookmark is necessary to prevent problems as otherwise hg-git pushes to the currently checked out branch, confusing Git. The snippet above will create a branch named hg in the Git repository. To get the changes in master use the following command (only necessary in the first run, later just use git merge or git rebase).

$ cd git-repo
$ git checkout -b master hg

To import new changesets into the Git repository just rerun the hg push command and then use git merge or git rebase in your Git repository.

.gitignore and .hgignore

If present, .gitignore will be taken into account provided that there is no .hgignore. In the latter case, the rules from .hgignore apply, regardless of what .gitignore prescribes.

Please note that Mercurial doesn’t support exclusion patterns, so any .gitignore pattern starting with ! will trigger a warning.

This has been so since version 0.5.0, released in 2013.

Further reading

See hg help -e hggit and hg help hggit-config.

Alternatives

Since version 5.4, Mercurial includes an extension called git. It interacts with a Git repository directly, avoiding the intermediate conversion. This has certain advantages:

  • Each commit only has one node ID, which is the Git hash.

  • Data is stored only once, so the on-disk footprint is much lower.

The extension has certain drawbacks, however:

  • It cannot handle all Git repositories. In particular, it cannot handle octopus merges, i.e. merge commits with more than two parents. If any such commit is included in the history, conversion will fail.

  • You cannot interact with Mercurial repositories.

Another extension packaged with Mercurial, the convert extension, also has Git support.

Other alternatives exist for Git users wanting to access Mercurial repositories, such as git-remote-hg.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hg-git-1.1.0b1.tar.gz (218.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hg_git-1.1.0b1-py3-none-any.whl (75.5 kB view details)

Uploaded Python 3

File details

Details for the file hg-git-1.1.0b1.tar.gz.

File metadata

  • Download URL: hg-git-1.1.0b1.tar.gz
  • Upload date:
  • Size: 218.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for hg-git-1.1.0b1.tar.gz
Algorithm Hash digest
SHA256 6705d801b210aa8aacbd0ad4aaa96286cda4ea2e6aeb7c23cdc0ed265b9b545d
MD5 67470b8c449f92b8e643f82fa8ba562f
BLAKE2b-256 d57b240aae75a9b73e6162dfe6fa58fe90b2399e32cbcb7b82ea7a597b5be967

See more details on using hashes here.

File details

Details for the file hg_git-1.1.0b1-py3-none-any.whl.

File metadata

  • Download URL: hg_git-1.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 75.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for hg_git-1.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a0f37b0fbd17834d44203ca9b8a87257b5c308f379b960d10aeb4c19cc23c10
MD5 eac952ec42787018f6ab089c55db383e
BLAKE2b-256 44e9d2e585b8032011bbda422e9e243b43c34b8dd81bea42b36e80cd93200b06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page