AzureDevOps - Link git commit or branch to work item via command line AzureDevOps - Link git commit or branch to work item via command line git git

AzureDevOps - Link git commit or branch to work item via command line


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:

Commit details

And you can see this in the work item details, in the "Development" section:

enter image description here


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"):

Repository Settings - Enable Commit Mention Linking

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:

Create branch link

Create branch dialog
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