Mirroring a HG project from Bitbucket to Github

GitMercurialWorkflowGithubBitbucket

Git Problem Overview


Is there an efficient workflow to mirror a project that is mainly hosted on bitbucket using Hg, to github?

Git Solutions


Solution 1 - Git

You could use a tool like hg-git to:

> - setup a Git repository somewhere that you have push access to,

  • and then run hg push [path] from within your project. For example:

    $ cd hg-git # (a Mercurial repository) $ hg bookmark -r default master # make a bookmark of master for default, so a ref gets created $ hg push git+ssh://[email protected]/schacon/hg-git.git $ hg push

> This will convert all our Mercurial data into Git objects and push them up to the Git server.
You can also put that path in the [paths] section of .hg/hgrc and then push to it by name.

hg-git

Solution 2 - Git

If you use Mercurial for a project you can quickly and easily make a git mirror of your project so that git users can contribute. I created a tutorial about using hg-git to manage Mercurial mirrors on GitHub.

It covers how to get started with a GitHub account, how to push up a project from Mercurial to GitHub, and how to accept contributions (pull requests) from GitHub. Here's a link to the blog post: http://hgtip.com/tips/advanced/2009-11-09-create-a-git-mirror/ archived at http://web.archive.org/web/20100811223113/http://hgtip.com/tips/advanced/2009-11-09-create-a-git-mirror/

Solution 3 - Git

> 'git-remote-hg' is the semi-official Mercurial bridge from Git project, once installed, it allows you to clone, fetch and push to and from Mercurial repositories as if they were Git ones:

Add git-remote-hg to your bin path. Then you can mirror as mentioned on github.

git clone --mirror  hg::https://bitbucket_repo

then, go into your cloned repo

git remote set-url --push origin https://github.com/exampleuser/mirrored

finally, sync your mirror

git fetch -p origin
git push --mirror

Solution 4 - Git

As of July 2013 there is BitSyncHub a web service for automating this process via a BitBucket post-receive hook. You will need to grant the service write permission to your GitHub repository though (add bitsynchub as a contributor).

Solution 5 - Git

I'm reporting from Feb 2019. I just encountered this problem, followed @vonc's suggestion to use hg-git, and filled a few missing steps to make it work. Here I'll provide a more detailed guide:

  1. Install hg-git by cloning its repository somewhere and making the 'extensions' section in your ~/.hgrc file look something like this:
[extensions]
hggit = [path-to]/hg-git/hggit

I found the most up-to-date installation instructions in the source repository: https://bitbucket.org/durin42/hg-git. So keep an eye that.

  1. Install dulwich if not already: pip install dulwich.

  2. Create a new empty repository on GitHub, for example https://github.com/user/git-mirror.

  3. Clone the hg source repository, and push it to the git mirror:

$ hg clone https://bitbucket.org/user/hg-source
$ cd hg-source
$ hg push git+ssh://[email protected]/user/git-mirror.git

Solution 6 - Git

One more available solution to quickly convert: https://github.com/frej/fast-export

Solution 7 - Git

You can use the Git-hg Mirror service to do this (including mirroring a GitHub repo to Bitbucket, or syncing bidirectionally).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSantaView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitSteve LoshView Answer on Stackoverflow
Solution 3 - GitjbtuleView Answer on Stackoverflow
Solution 4 - GitkynanView Answer on Stackoverflow
Solution 5 - Gituser10892982View Answer on Stackoverflow
Solution 6 - GitStefan GloutnikovView Answer on Stackoverflow
Solution 7 - GitPiedoneView Answer on Stackoverflow