Mirroring a HG project from Bitbucket to Github
Is there an efficient workflow to mirror a project that is mainly hosted on 开发者_如何学Gobitbucket using Hg, to github?
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.
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/
'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
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).
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:
- 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.
Install dulwich if not already:
pip install dulwich
.Create a new empty repository on GitHub, for example https://github.com/user/git-mirror.
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
One more available solution to quickly convert: https://github.com/frej/fast-export
You can use the Git-hg Mirror service to do this (including mirroring a GitHub repo to Bitbucket, or syncing bidirectionally).
精彩评论