In this lab, we will learn how to merge code from two different branches.

DevOps MPP Course Source

Prerequisites:

Lab Tasks:

  • Create a new branch for development
  • Merge changes from two branches with a pull request

Estimated Lab Time:

  • approx. 40 minutes

Task 1: Create a new branch for development

We will set up a new local branch for development and make changes

  1. Open your WideWorldImporters-RR project in Visual Studio and select Team Explorer. In the Home page, click Branches.

    In Team Explorer, under Project, Branches is selected.

  2. Right-click the master branch and select New Local Branch From

    On the menu, New Local Branch From is selected.

  3. Enter SalesRegionsBranch as the name and then click Create Branch.

    In Team Explorer - Branches, the Name field is set to SalesRegionsBranch. Master is selected from the drop-down menu, and under that, the check box for Checkout branch is selected.

  4. In the lower right corner of Visual Studio, the current branch is listed. Clicking the up arrow will show you the other branches.

    The menu for SalesRegionsBranch displays, with the following menu options: FeatureBranch1, master, New Branch, Manage Branches, and View History.

  5. Return to the Solution Explorer and add a new script to the project. Enter the following code in the script.

     ALTER PROCEDURE Website.GetOpenPurchaseOrderCount
     AS
     BEGIN
         SELECT
             [Open Orders] = COUNT(*),
             PurchaseOrderID
         FROM Purchasing.PurchaseOrders
         WHERE IsOrderFinalized = 0
         GROUP BY PurchaseOrderID;
     END;
     GO
    
  6. Save this file, click Deploy Project, then Commit All and Push the changes to VSTS using Team Explorer.

Task 2: Merge changes from two branches with a pull request

We will use VSTS to merge the changes from two branches.

  1. Open the VSTS project and select the Code menu. Ensure the master branch is selected. Notice that there is a gray bar that lets you know a branch was updated.

    In VSTS, on the Code menu, On the File tab, a message in a gray bar reads "You updated SalesRegionsBranch just now - Create a pull request.

  2. Click Create a Pull Request. This will open the New Pull Request page. This pages fills in a number of items from the pull request. You can alter the title and add more details to the description field. You can also use the Reviewers dialog to specify other users that should approve the request.

    On the Pull Requests tab, the New pull request page displays. The Description field has the added text, "alter proc to add orderid as part of the result set."

  3. Click Create. This will show you the pull request. You can approve and complete this yourself as part of this lab.

    On the Pull Requests tab, the description text displays as active. Two buttons enable you to either Approve or Complete the pull request.

  4. Click Approve. The left side will show who approved the PR.

    Under Reviewers is the message, sjones approved, with a green check mark.

  5. Click Complete. This will allow you to complete the merge. The title and description can be edited. You can also delete the branch after merging or squash the changes. Click Complete Merge.

    Under Complete pull request, the title and description of the pull request display. You have the options of either deleting SalesRegionsBranch after merging, or Squash changes when merging. Currently, neither are selected.

  6. The specific changes have been merged into the master branch. You can click the the Files menu area and find your changes in both branches.

Summary

In this lab you have completed the following tasks:

  • Created a new branch for development
  • Merged changes from two branches with a pull request