AzureDevOps - Link git commit or branch to work item via command line
GitAzure DevopsGit Problem Overview
I've worked on projects with a Jira integration where I simply had to include the ticket number in the commit or branch name and that work would automatically link with the ticket in Jira. Exe:
> git commit -am '123 some commit'
And on the ticket you'd see a link to the commit.
How can I do that with Azure Dev Ops?
I know how to manually do it via Visual Studio or in the ticket itself, but I want to do it through the command line only.
Git Solutions
Solution 1 - Git
You can link a work item in Azure Boards to a commit in Azure Repos by specifying the work item ID after a pound sign. Eg, to update work item #3, you need to mention #3
in the commit message. (The pound sign - #
is required, it won't parse bare numbers and try to link work items.)
For example:
git commit -m"Update bug #3"
Produces a bidirectional link between the commit and the work item. You can see this in the commit details, in the work item tab:
And you can see this in the work item details, in the "Development" section:
Solution 2 - Git
For those wondering why their commits aren't auto-linking to work items for some of their repositories - this is a feature you can turn on per repository:
Within Project Settings | Repositories navigate to the repository that isn't auto linking, and then under Settings enable "Commit mention linking" (and potentially "Commit mention work item resolution"):
You may find that this is disabled by default for Forks, whilst it's enabled by default for brand new repositories.
There is no way to automatically link branches to work items; unless you create the branch from the work item directly, using the "New Branch" button or "create a branch" link:
Note: This link only exists if there are no other Development links on the work item - you have to use the "Add Link" dialog after that.
There is an open ticket for that functionality: https://developercommunity.visualstudio.com/t/automatically-link-a-work-item-to-branches-when-co/809745