You are a Mercurial user and have little experience with Github. You are required to publish your Mercurial repository on Github. The good news is, you can do it without parting with Mercurial. There are bridges between Git and Mercurial. The one we are going to talk about today, is hg-git.
Let's start demonstrating our solution.
I do it on Bitbucket. We'll call this our canonical repository. Clone the repository.
hg clone ssh://email@example.com/bngsudheer/mycoolrepo
cd mycoolrepo/ echo "Sudheer Satyanarayana" >> contributors.txt hg add contributors.txt hg commit -m "Initial commit with contributors"
hg push ssh://firstname.lastname@example.org/bngsudheer/mycoolrepo
There are several ways to setup the mirror. One way to do it is importing the Mercurial repository to Gitbut. But in this article, we'll directly pull and push to Github repository. While creating the Git repository on Github, I chose the option - "Initialize this repository with a README".
Edit .hg/hgrc file in your repository and add these:
[extensions] hggit =
hg pull git+ssh://email@example.com:bngsudheer/mycoolrepo.git
Pulling for the first time from the newly created Git repository will create another head in your Mercurial repository. For example, running 'hg heads' shows:
changeset: 1:5b467a77b006 bookmark: master tag: tip parent: -1:000000000000 user: Sudheer Satyanarayana <firstname.lastname@example.org> date: Fri Mar 27 22:14:32 2015 +0530 summary: Initial commit changeset: 0:688bd09fe790 user: sudheer date: Fri Mar 27 22:07:26 2015 +0530 summary: Initial commit with contributors The changeset 1:5b467a77b006 is bookmarked as 'master'.
hg merge master hg commit -m "merging master"
Step 8: Push the changeset to the canonical Mercurial repository
Move the bookmark 'master' to default and push to Githib.
hg bookmark -r default master hg push git+ssh://email@example.com:bngsudheer/mycoolrepo.git
Now, you can adopt this method to work on the repository and keep pushing to both the repositories - The canonical Mercurial repository and the Github Git repository.
Work on the repository. Make some commits. Push to the canonical repository Move the bookmark 'master' to default and push to Githib Git repository If you do not move the bookmark, pushing to the Git repository makes no sense because hg-git will attempt to push the changeset the bookmark points to. In other words, the bookmark 'master' needs to be updated every time you want to push to the Git repository. You can automate the process of moving the bookmark to your latest line of work by activating the bookmark.
hg up master
That's it. Now your working method is:
Work on the repository. Make some commits. Push to the canonical repository Push to Githib Git repository Once the bookmark is active, Mercurial moves the bookmark to your latest line of work automatically.
Short repository name: For your convenience, you can give a short name to your Github repository URL. In your .hg/hgrc update the paths secion:
[paths] default = ssh://firstname.lastname@example.org/bngsudheer/mycoolrepo github = git+ssh://email@example.com:bngsudheer/mycoolrepo.git
Notes: Make sure not to add '.git' directory. Github will not accept the changeset if there is a '.git' directory.