SVN Branching – How to Work with Branches Using the Same Working Copy

branchingsvnversion control

We've just moved to SVN from CVS. We have a small team and everyone checks in code on the trunk and we have never ever used branches for development.

We each have directories on a remote dev server with the codebase checked out. Each developer works on their own sandbox with an associated URL to pull up the app in a browser (something like the setup here: Trade-offs of local vs remote development workflows for a web development team).

I've decided that for my current project, I'll use a branch because it would span multiple releases. I've already cut a branch out, but I am using the same directory as the one originally checked out (i.e. for the trunk).

Since it's the same directory (or working copy) for both the branch and the trunk, if for e.g. a bug pops up in the app I switch to the trunk and commit the change there, and then switch back to my branch for my project development.

My questions are:

  • Is this a sane way to work with branches?
  • Are there any pitfalls that I need to be aware of?
  • What would be the optimal way to work with branches if separate working copies are out of the question?

I haven't had issues yet as I have just started doing this way but all the tutorials/books/blog posts I have seen about branching with SVN imply working with different working copies (or perhaps I haven't come across an explanation of mixed working copies in plain English).

I just don't want to be sorry three months down the road when its time to integrate the branch back to the trunk.

Best Answer

No

It's not a sane way to work with branches. If you have uncommitted changes on the branch, and then switch your working directory to the trunk, those changes will still be present. If those same files were patched on the trunk, then you will have merge conflicts. It won't be long before you will commit a change to the trunk that was intended for the branch.

Disk space costs about ten cents per Gigabyte. Checkout the trunk and branch separately.

I do occasionally use svn switch as follows:

  • checkout tagged release to reproduce problem
  • create patch branch
  • svn switch to patch branch. The workspace should not change.
  • commit fix
  • create new tag

I also build on production systems from SVN checkouts. There I use svn switch to update to a new release, rather than getting a fresh checkout. I never toggle a single workspace between two separate branches.