Take the 2-minute tour ×

Recently I started working on a "portable" version of a project by copying all the files to a new directory. The portable directory differs from the stable directory only in terms of what has been deleted or commented out; nothing has been added.

I finally decided it's time to learn source control. Everyone says simply starting is more important than anything else, and I ultimately chose Mercurial since it's good for branching and (more importantly) I liked the tutorials I found online (e.g., http://hginit.com and http://hgbook.red-bean.com/).

I made a repository for my stable directory, and a clone in a central repository (Dropbox). I'm committing, pushing, etc. Now, however, I'd like to link my (already existing) portable directory with the central repository. I'd like to be able to, say, fix a bug in my stable code, push it to the central repo, and then pull the bug fix into the portable version--without changing anything else in the portable code.

I'm unsure what to do first with the portable code. If I clone the central repo to the portable directory, won't all my portable code be overwritten the first time I update the portable directory?

share|improve this question
please be careful about keeping a repo in drop box. It's not safe. Dropbox synchronizes files on its own terms, and Mercurial has very specific, well-tested, locking semantics that take into account hard links, network file systems, and transactional rollback. Mercurial's push and pull are the way to get changes from one machine to another -- not file synchronization. –  Ry4an Feb 7 '12 at 1:49
Please pay heed to Ry4an’s remark, it is a very dangerous place to keep your central repository. Since Mercurial takes care of sharing and versioning, there should be little need for a Dropbox. –  Laurens Holst Feb 7 '12 at 10:08

2 Answers 2

up vote 1 down vote accepted

You will need to clone the "central" repository to your portable directory before you will be able to do any work like you describe. However, an easy fix is to copy you portable directory somewhere else and create a new, empty folder. Then, clone your repository into that directory. After that, you should be able to just copy and paste your previous portable directory into the cloned version and allow it to overwrite the files there. That will allow you to commit those changes into version control and be in sync with the central repository.

If this method won't work, you will still have to clone the central repository and then make all of your "pending" changes to the existing portable location by hand to your new cloned version.

share|improve this answer

It sounds like the portable version should be a branch in your stable repo. Since you've already got an existing version that isn't in the repository I think the easiset way to do this is with the addremove command.

What I would do is first make sure any recent changes to your stable branch and make sure you've got a backup copy of your repo somewhere in case anything goes wrong. Then I would delete everything from your stable repository directory except for the .hg directory and any other repository management files such as .hgignore, .hgsub, .hgeol, etc. Then I would copy the portable version into that directory and run hg addremove. The addremove command will automatically add all new files and remove all missing files (which should be just removes in this case). Now I would mark this as a separate branch with hg branch <branch_name> where <branch_name> is whatever you want to name your portable branch. Then just hg commit as usual.

Now you've got your stable branch (called 'default' unless you've renamed it) and your new portable branch. Now when you make changes to the stable branch you can hg update to your portable branch and run hg merge default (or replace default with your stable branch's name) to merge those changes into the portable branch.

share|improve this answer

Your Answer


