Branches in Subversion Repositories

For medium to large projects, it is useful to maintain separate copies of the code to represent different stages of the development. These copies are called branches. A common approach is to have a main branch for unstable development where breakage occurs rather frequently. For each release, a separate branch is created from the main branch which is stabilized before the code is deployed. Sometimes changes need to be transferred between branches if development code needs to be included into a stable branch or if bugfixes need to be included into the development branch. This procedure is called merging.

In subversion, branches are represented by copies of a directory structure with a common history. They are created by one of the following command:

If you have fixed a bug in the 1.0 stable branch and need to merge it into the development branch, you need to do the following. It is assumed that the bugfix pushed the repository from revision 79 to 80, the branches are called trunk and 1.0 for the development and the stable branch, respectively.

  1. Check the changes: svn diff -r 79:80 URL/1.0 URL/trunk

  2. Merge changes: svn merge -r 79:80 URL/1.0 URL/trunk

In both commands, the -r 79:80 refers to revisions of the stable branch (the first parameter: URL/1.0).

Feedback is always welcome! If you'd like to get in touch with me concerning the contents of this article, please use Twitter.