Top Banner
Hands-On Lab Getting Started with Git using Team Foundation Server 2015 Lab version: 14.0.23107.0 Last updated: 9/22/2015
60

Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Jun 21, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Hands-On LabGetting Started with Git using Team Foundation Server 2015Lab version: 14.0.23107.0

Last updated: 9/22/2015

Page 2: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

TABLE OF CONTENT

GETTING STARTED WITH GIT USING TEAM FOUNDATION SERVER 2015...................................1

OVERVIEW.....................................................................................................................................3

Prerequisites...........................................................................................................................3

About the Fabrikam Fiber Scenario........................................................................................3

Exercises.................................................................................................................................3

EXERCISE 1: GETTING STARTED WITH GIT............................................................................................4

Task 1: Create Git Repository..............................................................................................4

Task 2: Clone Git Repository...............................................................................................8

Task 3: Commit Code and Link to Work Item......................................................................9

Task 4: Synchronize Commits with Server........................................................................17

EXERCISE 2: GIT BRANCHING AND MERGING.....................................................................................21

Task 1: Branching..............................................................................................................21

Task 2: Merging.................................................................................................................32

Task 3: Managing Security and Permissions.....................................................................40

Task 4: Branch Policies......................................................................................................43

Task 5: Code Review and Merge using Pull Requests.......................................................47

Page 3: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Overview

In this lab, you’ll learn about Git support in Team Foundation Server 2015 and Visual Studio 2015. Git is a distributed version control system. Git repositories can live locally (such as on a developer’s machine) and can now be hosted by Team Foundation Server. You will learn how to establish a local Git repository, which can easily be synchronized with a centralized Git repository in Team Foundation Server. In addition, you will learn about Git branching and merging support.

Prerequisites

In order to complete this lab you will need the Visual Studio 2015 virtual machine provided by Microsoft. For more information on acquiring and using this virtual machine, please see this blog post.

About the Fabrikam Fiber Scenario

This set of hands-on-labs uses a fictional company, Fabrikam Fiber, as a backdrop to the scenarios you are learning about. Fabrikam Fiber provides cable television and related services to the United States. They are growing rapidly and have embraced Windows Azure to scale their customer-facing web site directly to end-users to allow them to self-service tickets and track technicians. They also use an on-premises ASP.NET MVC application for their customer service representatives to administer customer orders.

In this set of hands-on labs, you will take part in a number of scenarios that involve the development and testing team at Fabrikam Fiber. The team, which consists of 8-10 people, has decided to use Visual Studio application lifecycle management tools to manage their source code, run their builds, test their web sites, and plan and track the project.

Exercises

This hands-on lab includes the following exercises:

1. Getting Started with Git

2. Git Branching and Merging

Estimated time to complete this lab: 30 minutes.

Page 4: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Exercise 1: Getting Started with Git

In this exercise, you will learn how to create, clone, and push commits to a Git repository with Team Foundation Server.

Task 1: Create Git Repository

1. Log in as Julia Ilyiana (VSALM\Julia). All user passwords are P2ssw0rd.

2. Launch Visual Studio 2015 from the taskbar and open Team Explorer. You should now be connected to the FabrikamFiber team project. If you are not automatically connected to the

FabrikamFiber project, select the Connect to Team Projects button ( ) to do so.

3. There are a few reasons why Fabrikam Fiber might want to use Git as their source control option within Team Foundation Server. One reason could be that they are collaborating with developers using a tool such as Xcode, which supports the Git protocol natively. Another reason could be that they have developers working offline (such as during a commute) who want to commit code locally when they are offline and check this code into Team Foundation Server when they get into the office. Microsoft now offers teams the ability to utilize Git without sacrificing the integrated application lifecycle management capabilities offered by Team Foundation Server. Visual Studio 2015 also provides developers with a great experience for working with any Git repository – whether it’s hosted by Team Foundation Server, a local repository, or another Git provider.

4. Select File | New | Team Project from the main menu.

5. Name the new project “FabrikamCommunity” and then select the Next button.

Page 5: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 1Creating new team project

6. Select the Next button to accept the default process template.

Page 6: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 2Creating new team project

7. Select the option labeled “Do not configure a SharePoint site at this time” and then select the Next button.

Page 7: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 3Creating a new team project

8. Select the Git version control system and then select the Finish button.

Page 8: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 4Creating new team project backed by a Git repository

9. After the new Git team project has been created, select the Close button to return to Visual Studio.

Task 2: Clone Git Repository

1. Select the Connect to Team Projects button.

Figure 5Location of Connect button

2. Right-click on the FabrikamCommunity project node and then select the option to Clone.

Page 9: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 6Cloning the repository

3. Accept the default endpoint and repository location and then select the Clone button.

Figure 7Clone repository to local folder

Task 3: Commit Code and Link to Work Item

1. In Team Explorer – Home, select the Settings tile.

Page 10: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 8Project settings

2. Select the Global Settings link.

Figure 9

Page 11: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Git settings

3. Enter an email address for Julia (julia.ilyiana@vsalm) and then select the Update button.

Figure 10Setting email address

4. Select the Home button in Team Explorer.

Figure 11Navigating home

5. Create a new work item for the product backlog by selecting Team | New Work Item | Product Backlog Item from the main menu.

Page 12: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

6. Enter a title of “Create new web site” and then select the Save Work Item button. Take note of the ID once the work item is saved.

Figure 12Creating new Product Backlog Item

7. In Team Explorer – Home, select the New… link underneath the Solutions section.

Figure 13Creating a new solution

8. In the New Project window, select the Visual C# | Web | ASP.NET Web Application template and then select the OK button.

Page 13: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 14Creating new web site

9. Select the MVC 4 template, de-select the option to “Host in the cloud”, and then select the OK button.

Page 14: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 15Creating a new web site

10. In Team Explorer – Home, select the Changes tile.

Figure 16Viewing changes

Page 15: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

11. Scroll down the list of included changes to the end and note that .gitattributes and .gitignore files were automatically added to the project. The .gitattributes file contains various settings to control Git behavior whereas the .gitignore file specifies patterns and extensions to ignore when detecting changes.

Figure 17Included changes

12. Enter a commit message of “initial MVC site for work item #247”. If the Product Backlog Item that you saved has a different ID, use that number instead. Typing ‘#’ followed by the work item ID will automatically link the commit to the work item when pushed to the server.

Figure 18Entering a commit message

13. Commit the changes by selecting the Commit button. Note that the commit is persisted locally and is not shared with the server.

Page 16: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 19Committing changes locally

14. Let’s make a small change to the web site. In Solution Explorer, open the _Layout.cshtml file from the Views | Shared folder.

Figure 20Opening _Layout.cshtml

15. Modify the title as shown in the following screenshot (from “My ASP.NET Application” to “Community”).

Page 17: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 21Modifying markup

16. In Team Explorer – Changes, enter a commit message and then select the Commit button. Save changes to files when prompted.

Figure 22Entering a commit message

Task 4: Synchronize Commits with Server

1. Navigate to the commits view by selecting the Sync link.

Figure 23Navigating to commits view

Page 18: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

2. The Team Explorer – Synchronization view shows both incoming and outgoing commits. Here we can see the two local commits that are ready to be pushed to the server.

Figure 24Outgoing commits

3. Select the Sync button to perform both a pull and a push to ensure we have the latest source before pushing our updates.

Figure 25Synchronizing with the server

Figure 26

Page 19: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Synchronizing with the server

4. Finally, let’s take a quick peek at what these commits look like in the web portal. In Team Explorer – Home, select the Web Portal link.

Figure 27Launching web portal

5. Select the Code tab in the web portal.

Figure 28Navigating to Code

6. Select the History tab to see the two commits. Note that the relative size of the commits (in terms of number of modified files) can be determined by viewing the size of the circles rendered to the left of the commits.

Page 20: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 29Commits view

Note: It may take a few moments after pushing a commit before the commit size indicators show up. You can refresh the page if necessary.

7. Select the link associated with the first commit.

Figure 30Selecting the first commit

8. Note that the “Create new web site” work item is linked to the commit. Select the link to open the work item.

Note: It may take a few minutes before the work item gets linked to the commit. In the event that the link has not been made yet, go ahead and continue on with the rest of the lab.

Page 21: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 31Viewing linked work item

Figure 32Viewing linked work item

Exercise 2: Git Branching and Merging

In this exercise, you will learn about Git branching and merging support in Visual Studio. In general, branching is often used to help switch development contexts and to isolate risk. Git branching is no different in that regard. Creating a Git branch is a lightweight (and therefore fast) operation, as you are simply creating a new reference to an existing commit. This is very different from Team Foundation Version Control (TFVC) branching where the entire source tree needs to be duplicated server-side. We will also take a quick look at the merging support for Git projects.

Task 1: Branching

1. Return to Visual Studio and open Team Explorer – Home.

2. Select the Branches tile.

Page 22: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 33Branches tile

3. Let’s say that we would like to create a new branch to do some development work on the web site. Right-click on the master branch node and then select New Local Branch From.

Figure 34Creating new local branch

4. Provide a name of Development, select the master branch, select the Checkout Branch option, and then select the Create Branch button.

Page 23: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 35Creating new branch

5. Note that you are now connected to the new local branch, and that it has not been published to the server yet.

Figure 36New local branch

6. In Solution Explorer, open the HomeController.cs file from the Controllers.

7. Modify the About method as shown in the following screenshot.

Figure 37Modifying source code from new branch

Page 24: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

8. In Team Explorer - Changes, enter a commit message of “dev version” and then select the Commit button. Save the changes when prompted.

Figure 38Commit changes

9. At this point, the changes have been committed locally. In the Team Explorer – Changes window, select the Development branch link to quickly navigate to the Team Explorer - Branches view.

Figure 39Switching between branches

10. Double-click on the Master branch and note that original version of the HomeController.cs file is shown in the code editor window.

Page 25: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 40Switching active branch

Figure 41Switching between branches

11. You don’t have to publish the branch to the server yet if you want to continue working locally. As you saw in the previous exercise, you can continue to work locally and add additional commits to the new branch. In Team Explorer – Branches, right-click on the Development branch and select View History.

Page 26: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 42Viewing history for local branch

Figure 43Source history for selected branch

12. When you are ready, you can delete the branch, merge it back into your master branch, or push it to the server-side repository so that teammates can access it. Let’s go ahead and publish the branch by right-clicking the Development branch and selecting the Publish Branch option.

Page 27: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 44Publishing branch

Figure 45Successful publication

13. Now let’s say that another team member makes a modification to the HomeController.cs file and commits that change to the master branch, before Julia has a chance to merge in her development changes.

14. Switch users and log in as Adam Barr (VSALM\Adam). All user passwords are P2ssw0rd.

Page 28: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

15. Launch Visual Studio from the taskbar.

16. Connect to the FabrikamCommunity team project (using the Manage Connections button as before, and this time select Manage Connections | Connect to Team Project).

17. Select the FabrikamCommunity team project and then select the Connect button.

Figure 46Connect to team project

18. Double-click on the FabrikamCommunity project shown in Team Explorer - Connect. Note that the Git project has a special icon.

Page 29: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 47Connect to team project

19. Clone the repository using default options as you did in the first exercise.

20. Open the Global Settings from Team Explorer – Settings as you did in the first exercise and add an email address for Adam. The email address that you use does not matter for the purposes of this demonstration.

Figure 48Setting up Git email

21. Double-click on the MvcApplication1.sln solution shown in Team Explorer – Home.

Page 30: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 49Open solution

22. Modify the same HomeController.cs file that Julia did, but this time change the text to be something different.

Figure 50Modifying web page title

23. In Team Explorer – Changes, enter a commit message of “Adam’s version” and then select the Commit button. Save changes when prompted. Note that Adam has committed changes to the master branch.

Page 31: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 51Commit changes

24. Select the Sync link.

Figure 52Sync changes with server

25. Select the Sync button.

Page 32: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 53Sync button

26. Switch users back to Julia.

Task 2: Merging

1. From Julia’s perspective, she has so far created a local branch based off the master, made a change to a file, and then published that branch. Julia would like to go ahead and merge her Development branch back into the master branch.

2. In Team Explorer – Branches, select the Merge dropdown.

Figure 54Merging Git branches

Page 33: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

3. Select Development as the source and Master as the target. Select the Merge button to start the merge process.

Figure 55Merging Git branches

4. Note that the Master repository is currently selected and that HomeController.cs shows the development version of the text. The merge was performed locally by updating the Master branch to point to the latest commit of the Development branch.

Figure 56Merge completed locally

5. Right-click on the Master branch in Team Explorer – Branches and select the View History… option. The history view should look identical to the one you saw earlier, except this time both the Development and Master branch designators (in red) point to the same commit.

Page 34: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 57Merge completed locally

6. Still unaware of Adam’s change that he pushed to the Main branch earlier, Julia will now attempt to push her commit. Navigate to the Team Explorer - Synchronization view and then select the Sync button to attempt a pull and a push with the server.

Figure 58Sync with server repository

Note: If you see a popup notifying that an open file has been changed externally, select Yes as this is expected.

7. Visual Studio reports that we can’t push our commit yet due to a conflict.

Page 35: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 59Conflict between two different commits

8. Select the Resolve the Conflicts link.

Figure 60Resolving conflicts

9. In the Team Explorer – Resolve Conflicts view, select the HomeController.cs file listed under the Conflicts section and then select the Merge button.

Page 36: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 61Starting manual merge process

10. The Merge window used for Git conflict resolution is very similar to the one used with Team Foundation Version Control. We will go ahead and assume that Julia’s change is correct, so check the box shown in the top-right pane.

Figure 62Merge window

Page 37: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

11. Select the Accept Merge button.

Figure 63Merge window

12. Select the Commit Merge button.

Figure 64Commit the resolved merge

13. In the Team Explorer – Changes view, note that conflicts have been resolved but the merge still needs to be committed. Enter a message and then select the Commit button. Save changes when prompted.

Page 38: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 65Commit the resolved merge

14. Select the Sync link.

Figure 66Unsynced Commits

15. Select the Sync button to finish the merge process.

Page 39: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 67Syncing with server

16. Select the Web Portal link in Team Explorer – Home.

Figure 68Opening the Fabrikam Fiber web portal

17. Select the Code tab.

Figure 69Navigating to Code view

18. Select the History tab to view all commits pushed to the repository.

Page 40: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 70Commits view

19. Select the Branches tab to view all branches published to the repository.

Figure 71Branches view

Task 3: Managing Security and Permissions

1. Now let’s take a quick peek at managing security and permissions for Git repositories hosted in Team Foundation Server. Select the FabrikamCommunity dropdown and then select the Manage Repositories link.

Page 41: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 72Managing repositories

2. The first thing to note is that you can create additional Git repositories within the same team project.

Figure 73Option to create additional Git repositories

3. Select the FabrikamCommunity repository node.

Page 42: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 74Navigating to repository node

4. You can manage repository level security here for your users and security groups.

Figure 75Managing repository security

5. Select the Master branch node. Security level settings that affect only the currently selected branch can be made here, providing fine-grained control for your repository if needed.

Page 43: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 76Managing branch security

Task 4: Branch Policies

When you want people on your team to review code in a Git team project, you can use a pull request to review and merge the code. Pull requests enable developers working in topic branches to get feedback on their changes from other developers prior to submitting the code into the master branch. Any developer participating in the review can see the code changes, leave comments in the code, and give a "thumbs up" approval if they're satisfied with those changes.

1. Navigate to the administrative section for the FabrikamCommunity project in the portal and then select the master branch. You should already be there if continuing on from the previous task.

Page 44: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 77Master branch

2. Although it is possible to utilize pull requests without any further configuration, let’s take a quick look at how to setup branch policies. Select the Branch Policies tab.

Figure 78Branch policies tab

3. You can make use of branch policies that effectively put in a gate that helps prevent inadvertent or low quality commits by automatically initiating a build, or by requiring code reviews by certain individuals. Select the option to “Require code reviews using pull request”. Note that the you could also set the minimum number of reviewers required here, although we will just use the default of 1.

Page 45: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 79Require code reviews

Note: It is also possible to configure branch policy such that a build is triggered whenever updates are made to the master branch. You can even have the merge fail when the build fails. This is useful for teams looking to adopt continuous integration.

4. It is also possible to require specific reviewers for specific portions of your code base. For example, let’s say that Julia needs to sign off on all changes made to the ASP.NET MVC controllers. Select the “Add a new path” link.

Figure 80Add required reviewers based on code path

Page 46: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

5. Leave the default options of Enabled and Required selected, set the Path to be everything in the Controllers folder, and then click on the Add User link.

Figure 81Add required reviewers based on code path

6. Select Julia Ilyiana from the Add Required Reviewers window and then select Save Changes.

Figure 82Add required reviewer

7. Select Save Changes to update the master branch policies.

Page 47: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 83Updating branch policies

Task 5: Code Review and Merge using Pull Requests

1. Switch users back to Adam and ensure that you are connected to the FabrikamCommunity project still.

2. In the Team Explorer - Branches view, double-click on master to change to that branch.

3. In the Team Explorer - Synchronization view, note that there are two incoming commits listed (if there are not, try a Fetch operation).

4. Select the Sync button to ensure that our local copy of master matches with the server. If you have HomeController.cs open in the editor, you will be prompted to reload it.

Figure 84Synchronize with server

Page 48: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

5. Now let’s say that Adam is working on the project and needs to update some of the controller code. To do this, he will first create a topic branch based on master. In Team Explorer - Branches, right-click on the master branch and select New Local Branch From…

Figure 85Creating local topic branch

6. For the branch name, use something like “users/adam/controllerupdate”. Use the default option to “Checkout branch”. Select the Create Branch button.

Figure 86Creating local topic branch

Page 49: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

7. Update the About method from HomeController.cs with a new message, something like “Adam’s enhanced description page.”

Figure 87Code update

8. In Team Explorer - Changes, provide a commit message and then select the Commit button. Save the changes when prompted.

Figure 88Commit change

9. In Team Explorer - Branches, right-click the topic branch and select Publish Branch.

Page 50: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 89Publish topic branch

10. After successfully publishing the branch, select the option to “Create a pull request”.

Figure 90Initiating a pull request

Page 51: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

11. In the web portal, review the pull request and then select the Create Pull Request button.

Figure 91Initiating a pull request

12. After the pull request is created, note that the pull request view shows what merge is proposed, Adam’s description is provided, and there are tabs listing affected files and commits. It also indicates that there are no merge conflicts detected, and that due to branch policy, Julia must approve the changes in order to proceed.

Figure 92Pull request view

Page 52: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

13. To demonstrate the branch policy in action, let’s say Adam attempts to complete the pull request by himself. Select the Complete Pull Request button.

Figure 93Attempt to complete pull request

14. When asked to confirm the merge, select OK.

Figure 94Attempt to complete pull request

15. Note that Adam is notified that the request first needs to be approved by all required reviewers first.

Page 53: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 95Attempt to complete pull request

16. At this point in the workflow, Julia needs to be notified of this pull request through some communication channel, whether that is in person, through Skype, through team room notification, or via TFS pull request alert. For the purposes of this short exercise, however, we will just skip to Julia checking pull requests for this project.

17. Switch users back to Julia.

18. In the web portal, navigate to the FabrikamCommunity project and the Code | Pull Requests view.

Figure 96Pull requests view

19. Select the Assigned to Me link.

Figure 97Viewing assigned pull requests

20. Select the link provided on the pull request from Adam.

Page 54: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 98Viewing pull request

21. At this point, Julia can review all of the files and commits associated with the pull request and make a decision. It is also possible for Julia to have a conversation with Adam (and perhaps other reviewers) in order to help make the decision, or perhaps even request additional work be performed before the pull request will be approved.

22. Let’s assume that Julia is ready to approve the request as-is, so select the response drop down underneath Julia’s name in the Reviewers section and select the Approved option.

Figure 99Approving pull request

23. Note that the Active section now shows that there are no merge conflicts and that required reviewers have indicated approval. Select the Complete Pull Request button to complete the pull request and merge changes from Adam’s topic branch into master.

Page 55: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 100Completing pull request

24. Note that the merge was successful, and that the associated commit is shown with a link. There is even the option to delete the source branch in order to assist with the cleanup of the associated topic branch.

Figure 101Completed pull request

25. Switch users back to Adam.

26. Refresh the pull request view and note that it has been updated as expected with the actions made by Julia.

Page 56: Getting Started with Git using Team Foundation …download.microsoft.com/download/6/2/B/62B60ECE-B… · Web viewHands-On Lab Getting Started with Git using Team Foundation Server

Figure 102Completed pull request

To give feedback please write to [email protected]

Copyright © 2023 by Microsoft Corporation. All rights reserved.