Walkthrough: Advanced Functionality of Source Control

This walkthrough demonstrates using branches, merges, and labels in Team Foundation source control.

Before proceeding with this walkthrough, it is important to have a fundamental understanding of branching, merging, and applying labels to source control items:

  • Branching   Branching in Team Foundation source control copies a specified set of files and folders on the Team Foundation server to a new location known as a branch. In essence, a branch creates new folders or files based on existing ones. Branching preserves the history of the folders and files that you are branching and allows changes to be merged from the old files to the new ones. Branching can be conducted through Source Control Explorer, or from the command line using the Branch Command. For more information, see Understanding Branching.

  • Merging   Merging is the process of combining two distinct versions of files, folders, or team projects located in separate branches. One branch is the source branch and the other is the target branch. The source branch contains the items that you wish to merge into the target branch. These folder and file versions can be based on changesets, dates, labels, workspaces, or the latest version. For more information, see Understanding Branching. Merging can be conducted through Source Control Explorer, or from the command line using the Merge Command.

  • Labeling   A label is a marker that you can attach selectively to a set of otherwise unrelated files and folders in your source control server to facilitate their collective retrieval to a workspace for either development or build purposes.

The procedures below will step you through performing a branch operation and then editing a team member's files in the resulting branch as well as the original branch. These edits will then be checked in and a merge will be performed. The merge will identify conflicts and you will resolve these conflicts. Additionally, you will also conduct the steps required to apply labels to a changeset in the final procedure.

Prerequisites

Before you can complete this walkthrough you must:

Required Permissions

To complete this walkthrough, you must have the PendChange and Checkin permissions. For more information, see Source Control Security Rights and Permissions.

Branching Source Control Items

The following procedure, describes how to perform a branch operation. Branching is a Team Foundation source control function to create new folders or files based on existing ones. For more information, see Understanding Branching and How to: Branch Files and Folders.

Warning

The following procedures assume that you have already completed the steps in Walkthrough: Exploring Team Foundation Source Control.

To branch items in source control

  1. On the View menu, select Source Control Explorer to open it.

  2. In Source Control Explorer, from the View menu, choose Other Windows, and then choose Source Control Explorer if not already open.

  3. In Source Control Explorer, navigate to the MyWindowsApp folder containing the MyWindowsApp.sln solution file you created in Walkthrough: Exploring Team Foundation Source Control, right-click, and choose Branch.

  4. In the Branch dialog box, in the Target text box, modify the location and name for the new branch by appending the end with Test Branch. You may also click Browse to navigate to a location.

    Note

    Target branches are automatically appended with the string "-branch."

  5. In the Branch from version section, in the By drop-down list box, choose Latest Version.

  6. Click OK, the new branch is created and presented in Source Control Explorer.

  7. Click the new branch folder called MyWindowsApp Test Branch. Notice that under the Pending Change column, each item in the new branch has a status of branch.

  8. Since a branch is a pending change, you must perform a check-in to apply the branch. Right-click the MyWindowsApp Test Branch folder and choose Check In Pending Changes.

  9. In the Check In dialog box, in the comment text box, type Test branch and click Check In.

    Note

    If your team project has check-in policies in effect, you may need to associate work items or check-in notes prior to continuing. For more information, see How to: Associate Work Items with Changesets and How to: Associate Check-in Notes with Changesets.

  10. The Pending Change column in Source Control Explorer displays blank entries indicating that your new branch is checked in.

You have now successfully created a new branch and checked it in; the next procedure will have you make changes to files in both the original and new branches.

Apply Some Changes to the Branches

Once you have completed the steps in the previous branching procedure above, you need to make some changes to a file on both branches so you can conduct a merge on the two branches and resolve the resulting merge conflicts. The following procedure steps you through checking out and editing files in both branches.

Check out and edit some files in the source control branches

  1. In the new branch created in the preceding step, expand MyWindowsApp Test Branch folder and in the right pane, locate the Class1.cs file you created in Walkthrough: Exploring Team Foundation Source Control, right-click, and choose Check Out For Edit.

  2. In the Check Out dialog box, click Check Out, you are returned to the Source Control Explorer with the file's Pending Change status changed to edit.

  3. Double-click the Class1.cs file to open it for editing.

  4. In the Class1.cs file, add the "New branch" string:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace MyWindowsApp
    {
          class Class1
          {
                string SourceControlMerge = "New branch";
          }
    } 
    
  5. In Source Control Explorer, right-click the Class1.cs file, and choose Check In Pending Changes.

  6. In the Check In dialog box, in the comment text box, type New branch changes and click Check In.

    Note

    If your team project has check-in policies in affect, you may need to associate work items or check-in notes prior to continuing. For more information, see How to: Associate Work Items with Changesets and How to: Associate Check-in Notes with Changesets.

  7. The Pending Change column in Source Control Explorer displays a blank entry for the Class1.cs file indicating that your edits have been checked in.

  8. Now, you need to make changes to the original branch. The steps are much the same as you just completed. In Source Control Explorer, navigate to the folder containing the original branch called MyWindowsApp.

  9. In the original branch, expand MyWindowsApp folder and in the right pane, locate the Class1.cs file you created in Walkthrough: Exploring Team Foundation Source Control, right-click, and choose Check Out For Edit.

  10. In the Check Out dialog box, click Check Out, you are returned to Source Control Explorer with the file's Pending Change status changed to edit.

  11. Double-click the Class1.cs file to open it for editing.

  12. In the Class1.cs file, add the "Original branch" string:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace MyWindowsApp
    {
          class Class1
          {
                string SourceControlMerge = "Original branch";
          }
    } 
    
  13. In Source Control Explorer, right-click the Class1.cs file and choose Check In Pending Changes.

  14. In the Check In dialog box, in the comment text box, type Original branch changes and click Check In.

    Note

    If your team project has check-in policies in affect, you may need to associate work items or check-in notes prior to continuing. For more information, see How to: Associate Work Items with Changesets and How to: Associate Check-in Notes with Changesets.

  15. The Pending Change column in Source Control Explorer displays a blank entry for the Class1.cs file indicating that your edits have been checked in.

Now that you have successfully created a branch and affected changes to both the original and new branches, the next procedure steps you through merging the changes from both branches.

Merging Source Control Items

After you have made changes to files in the branches, you can conduct a merge. The following procedure demonstrates merging with Source Control Explorer. For more information, see Understanding Merging and How to: Merge Files and Folders.

To merge branches in source control

  1. In Source Control Explorer, right-click MyWindowsApp Test Branch folder and choose Merge.

  2. In the Version Control Merge Wizard, in the Source Branch text box, the path and name for the MyWindows App Test Branch folder appears.

  3. In the Target Branch drop-down list box, select the MyWindowsApp folder.

  4. In Select the source branch changes you would like to merge, select All changes up to a specific version, and click Next.

  5. In the Select the version of the source items step, in the Version Type drop-down list box, choose Latest Version, and click Next.

  6. In the Perform the merge operation step, click Finish.

    Since there are differences between the source and target branches, the Resolve Conflicts dialog box appears; to continue resolving the conflicts, use the steps in the following procedure. If no conflicts are present when you perform a merge, the Resolve Version Conflict does not appear.

Resolving Merge Conflicts

Since there are differences among files in both branches, you are prompted to take action to resolve conflicts between the two branches. For more information, see How to: Resolve Conflicts. To resolve the merge conflicts, conduct the steps in the following procedure.

To resolve merge conflicts

  1. In the Resolve Conflicts dialog, click Resolve, the Resolve Version Conflict dialog box appears.

  2. In Resolve Version Conflict dialog box, in Resolution Options, choose Merge changes in merge tool, and click OK.

  3. In the merge tool, locate the conflict in the two files by clicking Next Change, the files are presented side-by-side showing the two strings (Original branch and New branch) you entered in the earlier procedure.

  4. Click the code containing the string New branch, the change is placed in the bottom pane.

  5. Click OK.

  6. In Microsoft Visual Studio dialog box, choose Yes to save the file.

  7. In the Accept Merged Result dialog box, click Yes to keep the merged file.

  8. In the Resolve Conflicts dialog box, click Close.

  9. In Source Control Explorer, right-click the MyWindowsApp folder, and choose Check In Pending Changes, the Check In dialog box appears.

  10. In the Check In dialog, click Check In.

    Note

    If your team project has check-in policies in effect, you may need to associate work items or check-in notes prior to continuing. For more information, see How to: Associate Work Items with Changesets and How to: Associate Check-in Notes with Changesets.

You have now successfully created a branch, made changes to both the original and new branches, merged the two together, and resolved resulting conflicts. The next procedure demonstrates how to use labels in Team Foundation source control.

Labeling Source Control Items

In Team Foundation source control, a label is a name applied to a specific set of revisions, often referred to as a snapshot build. Labels can only apply to one revision of a file. With a subsequent revision of a file, the label must either be removed, or a new label must be applied. Labels are a simple way to organize a set of files in a revision. For more information, see Working with Labels and How to: Apply Labels.

To apply labels to source control

  1. In Source Control Explorer, navigate to the MyWindowsApp Test Branch folder created in the earlier procedure, right-click, and choose Apply Label.

  2. In the Apply Label dialog box, in the Name text box, type MyWindowsApp label test.

  3. In the Comment text box, type Testing walkthrough.

  4. Under Items, click Add.

  5. In the Choose Item Version dialog box, make sure that the Look in list box contains the team project you are working on.

  6. Navigate in the MyWindowsApp Test Branch folder to locate the Class1.cs file and select it.

  7. In the list box, choose Latest Version.

  8. Click OK, the Apply Label dialog box displays with the items populated.

  9. Click OK.

See Also

Reference

Branch Command
Branches Command
Merge Command
Merges Command
Label Command (Team Foundation Source Control)
Labels Command
Pending Checkins Window

Concepts

Working with Labels
Working with Source Control Changesets

Other Resources

Team Foundation Source Control Walkthroughs
Branching and Merging Team Foundation Source Control