JavaScript Loaders

Wednesday, July 13, 2011

Quick Start with Mercurial and Bitbucket Hosting

I started my project rather unprepared - no version control, no hosting. But eventually I did my homework. I am going to use Mercurial DVCS (distributed version control system) and Bitbucket to host Mercurial (Hg) repository. I am quite confident that if you choose Google code or another hosting for Hg repo you can adopt the steps below with minor changes.

Let's call our project demo. It sits in a folder demo on my local drive. All I want is to enable Mercurial and start syncing it with Bitbucket repository. To accomplish just that we need just few steps.

  1. Install Mercurial. Make sure Mercurial command hg is in your classpath.
  2. Go to your project folder demo and run from command line:
    hg init
    You initiated brand new Mercurial repository that will contain files from demo project in a couple of steps.
  3. Create .hgignore file in demo folder to prevent Mercurial from adding files that don't belong to source control: build (or target with maven) folder, compiled classes, etc. For example see here.
  4. From command line in demo folder run:
    hg add
    You added all your files to Mercurial repository with exception of those identified by .hgignore.
  5. From command line in demo folder run:
    hg commit
    This is actual commit - without it those files that you added in the step before are just placeholders.
  6. We are done with initializing new Mercurial repository. If you don't want any hosting then you are done - your project is a Mercurial repository now. I recommend to read this to get started with Mercurial.

  7. Register on Bitbucket (Suppose you registered using name myusername).
  8. Create new repository and call it demo. This is your hosted Mercurial repository that you can access with url https://bitbucket.org/myusername/demo. Check with Bitbucket for exact URL.
  9. Update your remote repository (which is empty) with your existing demo files, from command line in demo folder run:
    hg push https://bitbucket.org/myusername/demo
  10. Save a push URL so that you don't need to enter it each time when you use hg push or hg outgoing commands. Locate hgrc file in demo/.hg folder (create if it doesn't exist) and add:
    [paths]
    default-push = https://myusername@bitbucket.org/myusername/demo
    

You've done it! Your lonely project just became both hosted (source code) and backed by enterprise-strength DVCS.