Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to programmatically create a new blank Bazaar branch/repo, tantamount to running brz init. I've tried several different routes from the bzrlib documentation but so far haven't succeeded.

These failures are listed below:

from bzrlib import repository
r ='/tmp/testing')
r = repository.Repository.create('/tmp/testing')

from bzrlib import branch
b = branch.Branch.create('/tmp/testing')
b ='/tmp/testing')

All result in failures that /tmp/testing is not a branch.

share|improve this question
up vote 2 down vote accepted

There's a nice convenience function hidden in there somewhere:

from bzrlib import bzrdir

Create a new ControlDir, Branch and Repository at the url 'base'.

This is a convenience function - it will use an existing repository if possible, can be told explicitly whether to create a working tree or not.

This will use the current default ControlDirFormat unless one is

I honestly don't remember how I found it. Probably by reading the code of a plugin.

share|improve this answer
This is amazing. Thank you! – Marco Ceppi Mar 15 '13 at 16:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.