{"id":12581,"date":"2016-03-02T20:58:33","date_gmt":"2016-03-02T20:58:33","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/?p=12581"},"modified":"2019-02-14T17:36:18","modified_gmt":"2019-02-15T01:36:18","slug":"linking-work-items-to-git-branches-commits-and-pull-requests","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/linking-work-items-to-git-branches-commits-and-pull-requests\/","title":{"rendered":"Linking Work Items to Git Branches, Commits, and Pull Requests"},"content":{"rendered":"<p>If you&#8217;re a developer working on a team that uses\u00a0Git, you&#8217;re probably using some form of topic branching to isolate your work. \u00a0If you&#8217;re using any of the Agile tools in Visual Studio Team Services, you probably also have a bug, task, or user story that&#8217;s tracking your development\u00a0work. \u00a0Until recently, the best way to keep these items related was to link your commits to your work items using a #ID mention in the commit message. \u00a0VSTS has some great new features that can make it much easier to track the relationship between your code and work.<\/p>\n<h2>New Development section on work items<\/h2>\n<p>In the new work item form, we&#8217;ve added a new &#8220;Development&#8221; section that surfaces the\u00a0related commits, branches, and pull requests. \u00a0This new section makes it easier than ever to see the links to the code that is associated with your work &#8211; and drilling in to the details of a commit or the feedback in PR is a click away.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/Development-section-populated.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12621\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/Development-section-populated.png\" alt=\"The Development section shows code related to a work item\" width=\"999\" height=\"542\" \/><\/a><\/p>\n<p>While displaying links more prominently is certainly useful, the Development section is more than just a place to show links. \u00a0Using the context of the linked items (or lack thereof), the section provides links to help developers take action. \u00a0I think an example works best to show the various capabilities&#8230;<\/p>\n<h2>Create a branch for your work<\/h2>\n<p>Let&#8217;s start at the beginning &#8211; you&#8217;ve been assigned some work, and you&#8217;re reviewing the story to understand the scope of your next task. \u00a0This story hasn&#8217;t yet been linked to any code, so there&#8217;s an action link to <strong>Create a new branch<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/create-branch-development.png\"><img decoding=\"async\" class=\"alignnone wp-image-12622 size-full\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/create-branch-development.png\" alt=\"Create branch from Development section\" width=\"228\" height=\"89\" \/><\/a><\/p>\n<p>Clicking the link shows the Create Branch dialog, and the\u00a0Work Items to Link section automatically includes the work item.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/create-branch-dialog.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12632\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/create-branch-dialog.png\" alt=\"Create a branch and link work items\" width=\"562\" height=\"431\" \/><\/a><\/p>\n<p>Once the branch has been created, the browser opens the new branch in the Code Explorer, and the branch is ready for development. \u00a0If you&#8217;ve already cloned the repo, you&#8217;ll need to fetch and checkout the remote branch locally before you can start work. \u00a0Visual Studio makes it easy to do this from the Branches page.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/vs-branches-checkout.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12651\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/vs-branches-checkout.png\" alt=\"Checkout branches from the Branches page in Visual Studio\" width=\"408\" height=\"343\" \/><\/a><\/p>\n<p>Checking out the new branch is also easy from the command line.<\/p>\n<pre>git checkout -b newbranch origin\/newbranch<\/pre>\n<p>In our example, the exact command would be:<\/p>\n<pre>git checkout -b users\/mateo\/cache-perf origin\/users\/mateo\/cache-perf<\/pre>\n<p>When changes are committed to the local branch and then pushed to the server, the Development section will show when the branch was last updated and who made the changes.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/development-branch.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12661\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/development-branch.png\" alt=\"Updated branch in the Development section\" width=\"232\" height=\"99\" \/><\/a><\/p>\n<h2>Creating a pull request<\/h2>\n<p>Now that\u00a0our branch has some changes, we can create a pull request. \u00a0In addition to the existing ways to\u00a0<a title=\"Create a pull request in VSTS\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/vs\/alm\/code\/git\/pull-requests\">create a PR<\/a>, the Development section provides an action link to <strong>Create a pull request<\/strong> when a branch is linked to a work item.<\/p>\n<p><span style=\"line-height: 1.5\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/development-create-PR.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12662\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/development-create-PR.png\" alt=\"Create a pull request from the Development section\" width=\"231\" height=\"109\" \/><\/a><\/span><\/p>\n<p><span style=\"line-height: 1.5\">Clicking the link jumps into the Create Pull Request experience with the source branch prefilled and the work item automatically included\u00a0in the Related Work Items section. \u00a0By creating the link from the branch to the work item, the Create PR experience is able to find our work item and automatically include it. \u00a0If the branch had commits that were linked to other work items, those work items would be included here as well.<\/span><\/p>\n<p><span style=\"line-height: 1.5\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/create-pull-request.png\"><img decoding=\"async\" class=\"alignnone size-large wp-image-12671\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/create-pull-request-1024x494.png\" alt=\"Create a pull request with linked work items\" width=\"879\" height=\"424\" \/><\/a><\/span><\/p>\n<p><span style=\"line-height: 1.5\">Once the PR\u00a0is created, the Related Work Items section shows the work items that are linked to the pull request. \u00a0More work items can also be linked from this section after a\u00a0PR is created.<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/pr-related-work-items.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12681\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/pr-related-work-items.png\" alt=\"View work items related to the pull request\" width=\"241\" height=\"107\" \/><\/a><\/p>\n<p>If we revisit the work item, we&#8217;ll also see that the Development section shows the link back to the PR.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/development-with-pull-request.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12691\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/development-with-pull-request.png\" alt=\"Development section with linked branch and pull request\" width=\"231\" height=\"122\" \/><\/a><\/p>\n<h2>Completing a pull request with a merge<\/h2>\n<p>When the review of the PR is complete and policies are passing, it&#8217;s time to merge. \u00a0In the Complete Pull Request dialog, the default description for the merge commit will include a list of the work items associated with the pull request. \u00a0This is useful for anyone viewing the commit history in the future to know which work items are related, no matter what tool they&#8217;re using to view history.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/complete-pull-request.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12692\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/complete-pull-request.png\" alt=\"Complete a pull request and link work items\" width=\"562\" height=\"427\" \/><\/a><\/p>\n<p>After the PR is merged, the related work items will be automatically linked to the merge commit. \u00a0The commit details view will show all of the linked work items.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/merge-commit-details.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12701\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/merge-commit-details.png\" alt=\"Merge commit details shows linked work items\" width=\"806\" height=\"263\" \/><\/a><\/p>\n<p>The Development section will show the PR (with the latest status) and the newly created merge commit.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/development-merged.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12711\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/development-merged.png\" alt=\"Development section shows linked pull request and merge commit\" width=\"232\" height=\"137\" \/><\/a><\/p>\n<h2>Linking to existing artifacts<\/h2>\n<p>We just saw how the new linking experiences work when starting work on a new branch &#8211; but what if you already have a branch that you want to link to a work item? \u00a0The work item form still has a Links tab where links to branches, commits, and pull requests can be created.<\/p>\n<p>Some developers find that they would rather link their work items as part of their development process. \u00a0In\u00a0Visual Studio, the Related Work Items section on the Changes page can be used to create links from commits to work items.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/vs-related-work.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12721\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/vs-related-work.png\" alt=\"Related work items in Visual Studio\" width=\"408\" height=\"263\" \/><\/a><\/p>\n<p>And those that prefer command line can always use a #ID mention to link a commit.<\/p>\n<pre>git commit -a -m \"Fixing bug #42 in the web client\"<\/pre>\n<p>No matter how you prefer to link your work to your code, those work items will be automatically linked when creating a PR. \u00a0And if you ever need to remove a link, that&#8217;s easy too.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/remove-work-item.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12722\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/03\/remove-work-item.png\" alt=\"Remove a work item link from a pull request\" width=\"242\" height=\"102\" \/><\/a><\/p>\n<p>All of these new features make the traceability between\u00a0work to code better than ever. \u00a0In the near future, we&#8217;ll have even more features to help trace your commits to branches, builds, and pull requests. \u00a0Stay tuned!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re a developer working on a team that uses\u00a0Git, you&#8217;re probably using some form of topic branching to isolate your work. \u00a0If you&#8217;re using any of the Agile tools in Visual Studio Team Services, you probably also have a bug, task, or user story that&#8217;s tracking your development\u00a0work. \u00a0Until recently, the best way to [&hellip;]<\/p>\n","protected":false},"author":198,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[227,1,225],"tags":[],"class_list":["post-12581","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-agile","category-devops","category-git"],"acf":[],"blog_post_summary":"<p>If you&#8217;re a developer working on a team that uses\u00a0Git, you&#8217;re probably using some form of topic branching to isolate your work. \u00a0If you&#8217;re using any of the Agile tools in Visual Studio Team Services, you probably also have a bug, task, or user story that&#8217;s tracking your development\u00a0work. \u00a0Until recently, the best way to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/12581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/198"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=12581"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/12581\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=12581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=12581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=12581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}