ON THIS PAGE
we will show you how to make code changes in a Git repository on Visual Studio Team Services to complete a work item assigned to you.
- You have read the Create a Backlog Page and the Plan Work Page and have a task and bug for the DeepSpace demo project assigned to you.
- You have created a Git Repository with the DeepSpace demo project code and cloned it following the steps outlined in the Getting Started walkthrough.
Throughout all of the webpages in this walkthrough, we will consistently use sample code written in Java and AngularJS. The project is called DeepSpace. All of our instructions in the walkthough webpages and the images (screenshots) provided will assume you are using this same sample code, but would also apply if you had your own code (with names changed appropriately).
Following the instructions below, you will make code changes for a work item assigned to you on your team backlog. We will lead you through the steps to: 1) Create a topic branch, 2) Make code changes, 3) Create a pull request, and 4) Verify the pull request validation build succeeds.
Create a Topic Branch
To start working on the DeepSpace task and bug assigned to you, you will create new topic branch in your repository.
A topic branch is a short-lived branch you create and use for a single feature or bug fix. In Git it is common to create, work on, merge and delete branches several times a day. So we will create a separate topic branch to work on the task and bug.
To create and publish a topic branch to Team Services, run the command provided below from your Git client from the root of the local Git repository. This is the repository you cloned from the DeepSpace demo project.
Create a new branch to work on your task (by using the "git checkout -b
and push your topic branch to Team Services (by using the "git push -u origin
topic_branch_name" command) as shown in this image:
You can view the branch created on Team Services from your team project page by selecting the
Code menu and then selecting the
Repeat the steps to create a new topic branch for fixing the DeepSpace bug assigned to you.
Make Code Changes
You can make small code changes in Team Services directly from your team project page by selecting the
Code menu, and then selecting the
Select your branch
topic_branch_name in the drop down at the top and find the file where the code changes have to be made. To implement the "Add Star Count Slider" task, browse to the file "/src/main/webapp/js/directives/FlyingStars.js".
Edit in the
Contents pane, make the code changes in the file. In "FlyingStars.js" uncomment line 44 to show the slider for the star count.
Provide a description of the change and click the
Save icon to commit the code changes. To associate the commit to the task, you can use the "#
taskID" notation in the description/commit message as shown in this image:
To fix the bug "Add Missing Earth", switch to the topic branch created for the bug fix. Browse to the "/src/main/java/com/microsoft/tfs/demo/ImageService.java" file and uncomment lines 60 - 64.
In the description field, use the "#
bugID" notation to associate the commit with the bug. Now click the
Save icon to commit the changes to the topic branch as shown in this image:
Being able to edit the code and save directly from the browser is very convenient for simple changes. But for changes that should be compiled and tested before commit, you can use the Eclipse Team Explorer Everywhere plugin or the IntelliJ plugin for Team Services.
Create a Pull Request
To prepare for merging your changes from your branch
topic_branch_name to the master branch, you will create a pull request.
You can create a pull request from your team project page by selecting the
Code menu, and then selecting the
Pull Requests submenu. You can then click either the
Create Pull Request button or the
New Pull Request button.
All the required inputs are filled in and you can optionally click on the
more options link to add code reviewers or update the description for the pull request. Click on the
Create Pull Request button.
Verify Pull Request Validation Build Results
Since you set up a build policy for pull requests when planning your work, a build is automatically started for the "DeepSpace.PR" build definition after a successful merge. You will see the status of the build on the pull request as shown in this image:
If the build is successful, you will be able to proceed with completing the pull request and merging the changes into the master branch.
- Learn how to Merge Changes - Learn how to merge the changes you implemented to the master branch on your Git repository in Team Services.
Frequently Asked Questions (FAQ)
Q: What if my pull request shows merge errors?
A: Merge errors can occur if there were changes in the master branch that conflict with changes you made in the topic branch. In that case you will need to merge those changes into your topic branch and resolve the merge conflicts manually.
Q: What if my pull request validation build fails?
A: Review the build log to identify the cause of build failure and make the fixes in the code. After the fixes are made the pull request is updated and a new build will be started automatically.