Friday 23 March 2012

Mercurial SCM on Dropbox

Mercurial is a simple distributed source control management tool. I won't discuss the necessity of using source control for any kind of software development.

I also won't compare it to other source control systems (Quick note: for a large multi-developer project you might want to figure out git, as it outperforms Mercurial in almost every way, except maybe the simplicity).

The basic tutorial on using Mercurial is also already written by Joel Spolsky at

This post is only a quick reference about, how you can start using it right away and share small proof-of-concept type projects between several computers (in case you are like me, geeky enough to do this kind of stuff in your spare time).

Introducing Dropbox - very convenient tool for sharing all kinds of files and synchronizing them between your desktop computer, laptop and whatever else. It is probably intended for synchronizing multimedia files, but can it also help working with source code? Yes it can, if you put your Mercurial repository in a Dropbox directory, it works like a charm.

Of course, if your project grows to more then one committer, than you probably should start thinking about more serious repository placement, as concurrent pushes might cause unpredictable results. But while you're alone, this is not an issue. Here is how you start.

1. Go to your Dropbox directory and create subdirectory for your project:
cd <dropbox>
mkdir <project>
2. Initialize Mercurial repository:
cd <project>
hg init
3. Go to your Projects directory and clone from Dropbox repository.
cd <Projects>
hg clone <dropbox>/<project>
4. Create .hgignore file and add everything you need to be ignored by Mercurial:
syntax: glob
5. Add files to Mercurial, commit and push to the Dropbox repository:
hg add *
hg commit -m "initial commit"
hg push
Alternatively, if you already use Mercurial locally in your project, replace steps 3 - 5 with specifying your dropbox repository in .hg/hgrc:
default = <dropbox>/<project>
You can now push/pull files to Dropbox repository, which will immediately upload changes to remote servers and your other Dropbox instances. Works both on Linux and Windows.

UPDATE: I've found that with Git this actually works exactly as easy. There are only few small differences:
1. In step 2, you need to pass additional "bare" parameter for Git to create a repository without working copy:
git init --bare
2. The alternative way to specify remote repository for Git is done like this:
git remote add origin <dropbox>/<project>
3. First commit to an empty remote repository is done like this:
git push origin master
Simple git push/pull will work for non-empty repository.

No comments:

Post a Comment