Take the 2-minute tour ×

I work mostly with Git and have a lot of code on github. I would also like to have it on Bitbucket, for people using mercurial but more importantly as I want to also have the code on my domian, and BItbucket supports Cnames for hosted code.

So is there a way for me to mostly work with Git, but also be able to push to HG.

Github created a project in other direction, (For HG repos to git), but is there one for the direction I am looking for.

share|improve this question
hg-git is two-way. –  Daniel Stutzbach Jul 10 '10 at 12:56
add comment

2 Answers

up vote 4 down vote accepted

If you're just doing a mirror of the Git repo(s), then you can set up a cron job to run the following script:




if [ $# -ne 1 ]; then
    for DIR in *; do
        if [ -d $DIR ]; then
            ./update.sh $DIR 2> $ERROR_FILE
            if [ -s $ERROR_FILE ]; then
                echo $DIR >&2
                cat -n $ERROR_FILE >&2
    echo $DIR
    cd $DIR

    if [ -a source ]; then
        cd source
        if [ -d .hg ]; then
            hg pull
        elif [ -d .git ]; then
            git pull
        elif [ -d .bzr ]; then
            bzr pull
        elif [ -d .svn ]; then
            svn up
            echo "$DIR is not a known repository type."
            return 1

        cd ..
        hg convert source hg

        cd hg
        hg pull $URL
        hg push $URL # You can add -f here if you don't mind multiple heads
        cd ..
        # hg dir or hg-git
        cd hg
        hg pull
        hg push $URL
        cd ..

    cd ..

    sleep 5

This assumes you have an SSH key installed. As you can see, it will mirror other VCSs as well. It assumes a directory structure like this:

    source/  # Original Git/Bazaar/SVN/Mercurial repo
    hg/      # Mercurial repo

Obviously, this is only one-way, but if you do all of your work in Git, then it won't matter.

share|improve this answer
add comment

I was going to add this to my other answer, but it got a little long, so we'll do it as a separate answer.

If you want to go both ways, you can use hg-git to get an hg version of the repo on your machine. You can still do all of your work in Git, it just means you'll be using GitHub as your intermediary.

$ cd src
# do some work
# push to GitHub
$ cd ../hg
$ hg pull
$ hg push bitbucket

However, it does have the benefit that if you want to pull changes from a Mercurial user, you can pull them into the hg repo, and push them out to GitHub.

$ cd hg
$ hg pull someotherrepo
  # Probably merge
$ hg push # Changes go to GitHub
$ cd ../src
$ git pull
  # Continue working in Git
share|improve this answer
add comment

Your Answer


