23
votes

My development team has worked with subversion for quite some time. The way that manage the trunk and branches is as follows:

  • We (almost) always release from the trunk

  • Each release gets its own branch.

  • When a release is ready for QA, we merge the branch back into the trunk and create a new branch for the next release.

  • Developers work off of either the trunk or the branch, but there are no developer-specific branches.

Lately, we have had some nightmare merging sessions, in part due to some major changes to the application. These don't always go smoothly and issues sometimes pop-up during QA where subversion did not merge quite right.

One solution might be to merge trunk changes into the release branch on a regular basis, say weekly, to ensure that the most up-to-date trunk changes are in the branch. Conflicts can then be fixed in closer to real-time.

What is your experience with this issue? Is there a standard best practice? Also, do you have a good way of keeping track of which revisions have been merged into the branch (decent comments in subversion could probably handle that).

5

5 Answers

15
votes

Firstly, I don't think there's a one-size fits all solution when it comes to managing code branches and releases. But to touch on a few of your points from my perspective:

  • Yes, I would merge changes from trunk into the release branch more often. Smaller chunks are always going to be more manageable than one large integration. And of course this means you're working against the latest most stable code.

  • Proactively teach people how to merge well. The developer who made the change should be doing (or be closely involved with) the merge. Understand what it is you are taking and what it should look like when it is finished. I too often see people run a integration without really knowing what they are doing and what they are expecting as the result.

  • Perhaps you want to have an integration branch that isn't trunk. This can be tested daily and any issues caught here before they go and break trunk and scare everybody.

13
votes

So assuming I've got your model right here: You develop major changes to the project in a branch (off of trunk) which can get quite old.

You continue to do other development on trunk which always holds the 'live' software, so these changes are minor updates and bug fixes. You're getting problems when you merge the monumental development branch back into trunk.

You can only effectively manage 2 concurrent product versions with that model, which may be enough for now, but might bite you in other ways anyway and will get worse if you ever need to manage 3 or 4 versions. Can I suggest inverting the way you work?

Have a Version branch for each release. This should be branched from trunk (at any revision). The only way you modify the version branch is to merge in revisions from trunk.

This means you can work primarily on trunk instead of in a large development branch. You also apply your bug fixes directly to trunk - so you've got no major integration issues being stored up for the next release. To release bug fixes to the previous versions, just merge the required trunk revisions into the appropriate Version branch.

This way you can keep everything you want to release in branch, but only actually ever release what you're happy with, because that's all you merge in to the version branch.

You can still take development branches if you need, but you can keep them targetted and small, perhaps individual features rather than large projects.

This will allow you to manage multiple versions in a sane way and keep a good track of what's in each release using svn's merge-info.

5
votes

Our experience is to clearly differentiate:

  • development branch
  • consolidation branch (branch used to consolidate development we are sure to go into production

Trunk is only for recording stable released version, from which we can branch.

In the "development branch", we can manage important changes, included some which will not end up in the next release (because too complex, not ready in time, dependent on other late developments, ...)

The consolidation branch represents the final steps (note the plural) needed to finalize the release. It happens after a meeting where all the features needed to be delivered are validated.

We only merge into the "consolidation branch" what we are sure to put into production. We go on that branch until the final release.

2
votes

Totally agree with Andy: There's no "one-size fits all solution", but the issue shouldn't be keeping your release branch up to date, rather the other way around.

Good change control should keep your branch from being volatile. Gating issues should be fixed on the release branch and then merged to the trunk immediately. Be ready for this "merge" to be non-trivial, the release gating issue may not even exist on the trunk but you need to do an analysis and test for it anyawy.

It sounds from what you say that you are developing on your branch and then merging all at once to your trunk just before you release and just crossing your fingers. I wonder how many bugs you are introducing by doing this.

2
votes

First, I wholeheartedly agree with the previous responders that there is no one-size fits all solution.

In our case, we have many relatively small applications, with each application normally having only a single developer. When we do engage in collaborative development, there tends to be only 2 to 4 developers.

Our general policy is:

  • The trunk contains the current project state;
  • We use branches for developing new features, bug fixes, etc. Branches are merged back to the trunk when complete;
  • To release, we create a tag from the current trunk and release the tag.

Andy also made an important point that needs emphasizing: "Proactively teach people how to merge well." Many, if not most of our problems seem to arise from poor merging practices.