Branching & Merging in 2010

Branching & Merging has always been difficult. I have worked with teams who go out of their way not to branch the code. However sometimes it’s just necessary. Thanks to the Software Engineers at Microsoft it’s much easier now in TFS 2010 Source Control. I don’t mean easier (less key strokes) I mean easier because a Branch is now a first class citizen and there are ways to visualize what change sets have made it into which branches.

Let me show you what I mean.

Lets take a simple application like my calculator and create two branches of the code for the purpose of code promotion. Some source control tools have the concept of a promotion model. Which works kind of like static labels. Code can be promoted from development to QA and Production branches. Dev QA and Production act like labels but there is only ever one Dev, QA and Production promotion level at a time. We can use branching to achieve this. I’m not promoting this method as the way you should promote code, I’m just using it as an example for branching because I think it’s pretty easy to get your head around.

To start I’ll take my Calculator solution and create two branches in source control called QA and Prod. Right click on the project folder in Source control and select Branching and Merging | Branch…

image

On the branch dialog enter the name of the target branch.

image

Create two, one named QA and one named Prod. You will also be asked to create a local folder if you leave the option checked to store it on your local workspace. Don’t forget this operation is a local change and you will have to check in your changes to make it permanent.

Once all is complete you should have the following in Source control.

image

So here we have the Calculator main branch and of course the two promotion branches Prod and QA. Right click on Calculator and select Branching and Merging | View Hierarchy from the popup menu. This will give you a view of the relationships between branches.

image

Right click on the main branch and select Properties from the popup menu. The properties dialog contains information about the branch including relationships to other branches and permissions. This is where you can denote who has the rights to promote to a particular branch.

image

We can use the History View to visualize which branches a changeset has been promoted to. Here are the changesets checked into the my calculator.

image

If you right click on one of the changesets we can see how it has been promoted through the branches. Lets take this bug fix for example. I’ll write click on it and select Track Changeset from the popup menu.

Next we select which branches we want to look at.

image

Click on Visualize to see which branches this Changeset is in. From the Visualizer switch to Timeline Tracking to get this view.

image 

We can see that the changeset has been promoted to both branches. Therefore Changeset 13, 15 and 16 are the same.  Select a changeset and you will see the date and time the changeset was merged into the branch at the top highlights in yellow.

Now try this. Make a change in the base branch then open the visualizer and drag the base branch to one of the other branches this will merge the changeset into the branch you drop it on. Then check in your merge and refresh your visualizer.

Happy Branching and Merging.