55

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

CoderHawk
  • 3,771
  • 3
  • 36
  • 57
Santa
  • 10,797
  • 8
  • 46
  • 64
  • See also http://stackoverflow.com/questions/883452/git-interoperability-with-a-mercurial-repository – wimh Dec 02 '10 at 15:29

7 Answers7

40

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://git@github.com/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

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Thanks. I did take a brief look at hg-git, but I see that it is still in an alpha state. I tried installing it in cygwin but I am having some stability issue with it at the moment. Provided this works, though, it is definitely a useful tool in the workflow. – Santa Apr 19 '10 at 20:23
13

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/

ecm
  • 2,092
  • 2
  • 15
  • 22
Steve Losh
  • 19,008
  • 2
  • 48
  • 44
12

'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
jbtule
  • 29,889
  • 11
  • 91
  • 126
6

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).

kynan
  • 11,847
  • 6
  • 71
  • 79
3

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://git@github.com/user/git-mirror.git
qobilidop
  • 124
  • 2
  • 6
1

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

0

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

Piedone
  • 2,535
  • 20
  • 42