Developer, entrepreneur, drummer, biker, dog owner, husband, and proud dad. Loves Laravel and coffee
Using BitBucket and GitHub with hg-git
I’ve been using Mercurial and BitBucket since 2010 and my experiences have been really great with it. BitBucket has a great service and Mercurial is very easy to use. However, within my need to learn new and different things (and seeing everyone else use it), I decided to take a look at Git and GitHub. The reason I initially went with Mercurial over Git is because EllisLab/CodeIgniter was initially using it too (they have since moved to Git), but I also found it easier to use and understand compared to Git. Now it seems like Git and the services and resources around it have improved a lot, so I figured I would try it out.
The first thing that I wanted to accomplish is to be able to copy my public BitBucket repos over to GitHub. After doing some looking around, I came across this brilliant blog post/video done by Phil Sturgeon. However, I was having some trouble setting everything up on my systems – so I figured I would write about it to hopefully help some of you out too.
Take existing BitBucket repos and mirror them on GitHub
Use BitBucket/GitHub together without too much work moving forward
Use multiple development environments (PC/Mac)
Open the terminal and run: easy_install hg-git
Edit your ~/.hgrc file to make sure it includes:
Edit your local repo’s hgrc file to look like:
default = ssh://email@example.com/modomg/codeigniter-pagination
gh = git+ssh://firstname.lastname@example.org/modomg/codeigniter-pagination.git
Note that we are keeping the BitBucket location as “default”, this is so that you can work with this location without using a specified name. Also note that our GitHub location is named “gh” and also has a “git+” prefix to the URL string…this is very important!
Open a terminal/command prompt pointing to your local repo and enter the following: hg gexport
If you look in your .hg directory now, you will see that there has been a “git” directory and a “git-mapfile” added
Now to see if everything works, enter: hg push – which should connect you to BitBucket and return that there were no changes found (assuming nothing changed).
To push everything to GitHub, enter: hg push gh – which should connect and push everything to GitHub
Check your GitHub repo and you will see that everything has been replicated: files, commits, tags, branches, etc
Now that you have properly set up a replicated repo on your system you can now work with Mercurial/TortoiseHG/BitBucket as usual. When you would like to move everything up to GitHub, just open the terminal and enter the hg push gh command and you will be all set!
Note: You can also use this similar process if your initial repo is on GitHub and you would like to replicate it on BitBucket.