Entries tagged “Mercurial”

Using Bitbucket's free plan efficiently

written by cryzed, on May 13, 2010 8:11:00 AM.

Bitbucket’s free plan might seem a bit limiting by only offering one private repository – but it is, in fact, easy to circumvent these restrictions and enjoy most of the benefits the paid plans have to offer.

Instead of having multiple private repositories you can simply create a new branch for each of your projects and then, depending on what project you are currently working on, simply hg update the project to use the right branch and commit the changes you made only to that branch.

If you use your private repository that way having a default branch may seem useless but I keep it anyways – that way, when cloning the repository, I’m always on the default branch and can then simply hg update to another branch. To create the default branch you need at least one non-empty commit though – so I simply created a .placeholder file in the default branch and made my Initial commit.

Here’s a sample bash-session that should show you how to set up such a basic private repository structure:

hg clone ssh://hg@bitbucket.org/username/private
cd private
touch .placeholder # The work-around for the non-empty commit
hg add .placeholder
hg commit -m "Initial commit" # This creates the default branch
hg branch project
hg remove .placeholder # Remove the .placeholder file from the default branch
touch file
hg add file
hg commit -m "Initial commit" # Initial commit for the project branch
hg push -f # Push the changes to Bitbucket; -f is needed to create a new branch

Now you have successfully set up a private repository with 2 branches: default and project. Try deleting the repository locally and then cloning it again. When listing the directories’ contents you should only see the .placeholder file since you are, by default, always on the default branch after cloning. To get to your project branch simply do: hg update project and you should see the file we added appear in the directory.

Of course there is a big disadvantage using a repository like that which may not be quite apparent at once. Assume you use that private repository to store some of your private projects. And with private I really mean private. What do you do when you want to work on a private project with a team? They would need to clone your private repository and of course all the branches along with it – that means you can’t restrict user access and they could easily browse through all your files by switching to another branch. With multiple private repositores that would of course be no problem: So you may still want to consider buying one of the non-free plans.

That being said, I really don’t want to discourage people from buying the non-free plans, but if you are the only person that needs access to your single private repository, the method shown above is a handy and efficient way of using it.

Thanks to name for proof-reading and suggesting corrections.