Garry Pilkington


Application Developer
Liverpool, UK

Branching and Merging with TortoiseSVN

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
    1 - 1

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

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

  7. Make any changes to trunk
    1 - 4

  8. Commit any changes
    1 - 5

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
    2 - 1

  2. Choose ‘Merge a range of revisions’
    2 - 2

  3. In ‘URL to merge from’ choose your trunk
    2 - 3

  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
    2 - 4


    2 - 5
  5. Click merge. Now we have the opportunity to edit that conflict
    2 -5 - a

  6. This will open up TortoiseMerge which will allow us to resolve the issue. In this case I want both changes.
    2 -5 - b


    2 -5 - c


    2 -5 - d

  7. Perform an Update then Commit
    2 - 7 - a


    2 - 7 - b

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

Merge Branch with Trunk

  1. Switch working copy by right clicking project root in Windows Explorer > TortoiseSVN > switch3 - 3

  2. Switch to the trunk then ok
    3 - 4

  3. Right click project root in Windows Explorer > TortoiseSVN > merge
    3 - 5

  4. Choose ‘Reintegrate a branch’
    3 - 6

  5. In ‘From URL’ choose your branch then next
    3 - 7

  6. Click ‘Test merge’, this shouldn’t show any conflicts
    3 - 8

  7. Click Merge
  8. Perform Update then Commit
    3 - 10


    3 - 10 - a

  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.

Comments

EtienneT said:

This will work for simple branch, but as soon as this becomes complicated, you'll suffer and you'll have conflicts everywhere.  For branching and merging, mercurial or git is the way to go.

# May 19, 2010 3:42 PM

Twitter Trackbacks for Branching and Merging with TortoiseSVN - Garry Pilkington [asp.net] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Branching and Merging with TortoiseSVN - Garry Pilkington         [asp.net]        on Topsy.com

# May 20, 2010 12:49 AM

capgpilk said:

@EtienneT - Yes this is a simplified method showing basic branching. It is ideal for small teams where branching is infrequent.

# May 20, 2010 3:22 AM

Harsh said:

At last, a simple and effective article that clearly explains how to go about merging using TortoiseSVN. Thanks a lot!

Regards,

Harsh.

# July 26, 2010 6:49 AM

capgpilk said:

@Harsh - Thanks, I plan on expanding this to cover basic operations using TortoiseSVN and compare SVN with Mercurial.

# July 27, 2010 4:24 AM

Chen said:

The article is very nice, and we started using branching and merging procecss. It is quite easy than expected.

thanks for a good article.

# December 13, 2010 10:21 PM

Deutsch said:

Very good.

Tank you very much.

Deutsch.

# March 28, 2011 8:20 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)