How to work in a branch under Subversion source control

And how to merge back to the trunk safely


A common cause for headaches when dealing with version control is the process of merging a branch of code back into the trunk. As a brief primer, software developers will use version control systems to manage changes in their code and allow for multiple developers to work on the same project at the same time. One developer will check out a copy of the code, make changes, and commit them back into the code repository. Meanwhile, another developer can commit the same file back to the repository and the version control system will merge them together (hopefully). There are several popular source control systems (see Git and Mercurial) but in this case I'll be talking about Subversion (or SVN as it's abbreviated).

The main version of the software is commonly called the trunk. This is the codebase used in the production version of the software. It's common for developers to work directly in the trunk when they are making minor changes to the code. Whether they should or should not do that is up for debate. When a new feature comes down the pipeline that will take a significant amount of time to program, it usually makes sense to branch off from the trunk so that developers can work on this feature without interrupting any important changes that need to be made to the trunk code.

When a developer branches off from the trunk, they are creating a copy of the trunk at the point in time that they chose to branch. From there, they can work on and test the new feature in this separate copy of the code. It's important however that the branch version does not get too far out of sync from the trunk version. If you're working on a large feature that might take a month to develop, you don't want to wait until you're done programming to start bringing yourself up to date with the trunk. If you do, you'll increase the number of, and complexity of, code conflicts. Instead, you periodically want to merge the latest version of the trunk back into your branch.

Merging the changes that have been made in the trunk (or any other branch) into your development branch is known as merging a range of revisions. The trunk is not affected by this operation, it's simply bringing into your branch everything that is new since you branched off. You can do this as frequently as you like while you're working on a branch, but it's essential that you do it once just prior to merging the branch back into the trunk.

Join us:






Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Ask a Question