tags:

views:

349

answers:

3

I've been playing around with Git recently to get a grasp of distributed version control. Now I'm looking at Bazaar, but can't figure out how to make a local branch, i.e. a branch that I do not have to push to when I want to commit changes. With Git, I would do

git branch branch_name

or

git checkout -b branch_name

I can then work in my local branch, committing changes as I go, without having to push changes to a remote repo. When I'm through with the branch, I can merge it to my local master branch. If I want, I can then push those changes to the remote repo.

Is this possible with Bazaar? Bazaar seems much more like SVN, with branches just being separate directories, so maybe not.

+2  A: 

Yes, you definitely can do that.

Let's say there's a remote repository at bzr+ssh://foo.com/repo/mainline

You can create a local branch by doing:

bzr branch bzr+ssh://foo.com/repo/mainline local_branch

Now, you can make changes to the local_branch and commit them, and those changes are only in that local directory. e.g.:

cd local_branch
touch foo
bzr add foo
bzr commit -m "Add foo."

That will add foo only in the local branch.

Pete
I think the "cd" part of that validated the "branches just being separate directories" part of the question. Branches are less useful if I have to reconfigure my tools when I change branches.
Dustin
A: 

bzr differs from git in that you can't switch the branch represented by the working directory. You can branch from your working directory, though, instead of having to branch from the remote repository. So instead of

git clone git+ssh://foo.com/repo
cd repo
git checkout -b new_branch

you would do

bzr branch bzr+ssh://foo.com/repo
bzr branch repo new_branch
jamessan
"bzr differs from git in that you can't switch the branch represented by the working directory." Does this mean that bzr projects are usually set up with trunk/ and branches/ subdirectories, like in typical SVN projects?
ThisSuitIsBlackNot
Sort of, but not in the rigid sense that is associated with SVN and the directories aren't part of the actual repository. Instead, a user simply publishes their branch online somewhere and other people are able to access it, merge from it, etc. If a common location is being used to host the branches (like launchpad), then you'll be able to easily see all the published branches associated with a project. Even though the different branches know about each other (via the history of commits and knowledge of which repository they were branched from), they are all their own distinct repository.
jamessan
A: 

If you set up your repository the correct way, you can work in a similar fashion to git.

cd ~/dev
bzr init-repo
bzr reconfigure --with-no-trees
mkdir branches
bzr branch bzr+ssh://foo.com/repo branches/mainline
bzr checkout --lightweight branches/mainline working

This will create a structure like so:

/dev
    /branches
        /mainline
        <other branches go here>
    /working
        <this is your working tree>

And if you want to make branches, you can do the following:

cd ~/dev/checkout
bzr branch --switch ~/dev/branches/mainline ~/dev/branches/some-feature

and now you'll be in the some-feature branch, which will be at the same point as mainline.

FryGuy