Branching and merging while using a source control system such as Subversion can sometimes catch people out, so here is a quick and dirty guide to cover the basics. For this example I am using Visual Studio 2010, TortoiseSVN 1.6.6, Subversion 1.6.6 and AnkhSVN 2.1.7819.411, so if you are using different versions, some of these screen shots may differ. This is assuming you have your code checked in to the trunk directory and have a standard SVN structure of trunk, branches and tags. There are a number of developers who prefer to develop solely in a branch and never touch the trunk, but the process is generally the same and you may be on a small team and prefer to work in the trunk and branch occasionally. There are three steps to successful branching. First you branch, then when you are ready you need to reintegrate any changes that other developers may have made to the trunk in to your branch. Then finally when your branch and the trunk are in sync, you merge it back in to the trunk.

Branch

  1. Right click project root in Windows Explorer > TortoiseSVN > Branch/Tag
    11_thumb_03332E9D

  2. Enter the branch label in the ‘To URL’ box. For example /branches/1.1
    12_thumb_5C44CCC2

  3. Choose Head revision
  4. Check Switch working copy
  5. Click OK
  6. Make any changes to branch
    13_thumb_74581150

  7. Make any changes to trunk
    14_thumb_7A030529

  8. Commit any changes
    15_thumb_12827CAD

For this example I copied the project to another location prior to branching and made changes to that using Notepad++. Then committed it to SVN, as this directory is mapped to the trunk, that is what gets updated.

Merge Trunk with Branch

  1. Right click project root in Windows Explorer > TortoiseSVN > Merge
    21_thumb_7EE4F73E

  2. Choose ‘Merge a range of revisions’
    22_thumb_264B9DDC

  3. In ‘URL to merge from’ choose your trunk
    23_thumb_298CE9EA

  4. Click Next, then the ‘test merge’ button. This will highlight any conflicts. Here we have one conflict we will need to resolve because we made a change and checked in to trunk earlier
    24_thumb_2EEB34C1
    25_thumb_6719860C

  5. Click merge. Now we have the opportunity to edit that conflict
    25a_thumb_0698B015

  6. This will open up TortoiseMerge which will allow us to resolve the issue. In this case I want both changes.
    25b_thumb_7A767446
    25c_thumb_4CE52EB6
    25d_thumb_26DF5893

  7. Perform an Update then Commit
    27a_thumb_707E0AB6
    27b_thumb_26FB902E

  8. Reloading in Visual Studio shows we have all changes that have been made to both trunk and branch.
    28_thumb_672183DB

Merge Branch with Trunk

  1. Switch working copy by right clicking project root in Windows Explorer > TortoiseSVN > switch
    33_thumb_44D95288

  2. Switch to the trunk then ok
    34_thumb_1C4A4AA7

  3. Right click project root in Windows Explorer > TortoiseSVN > merge
    35_thumb_51EF6A34

  4. Choose ‘Reintegrate a branch’
    36_thumb_79759AC4

  5. In ‘From URL’ choose your branch then next
    37_thumb_3AB07791

  6. Click ‘Test merge’, this shouldn’t show any conflicts
    38_thumb_0BDA9922

  7. Click Merge
  8. Perform Update then Commit
    310_thumb_3DE19DD2
    310a_thumb_7869711B
  9. Open project in Visual Studio, we now have all changes.
So there we have it we are connected back to the trunk and have all the updates merged.