There are many teams who use GitHub (https://www.github.com) for version control.
Besides version control, these teams require services of Build, Packaging, Release Management and Progress Boards for product management.
Azure DevOps offers all these services. Azure DevOps also offers its own implementation of Git, built-in to it.
Some teams that are already using GitHub for version control, are happy to continue to use GitHub and do not want to migrate their code to Azure DevOps – git. In such situations, it becomes necessary to integrate their GitHub repositories with Azure DevOps to leverage the best services of both of them.
In this article, we are going to see the following:
1. Connect GitHub from Azure Boards (Part of Azure DevOps) with proper authentication and authorization set.
2. Integrate Azure Boards with GitHub to link various entities of GitHub Repository like Commits, Pull Requests and Issues with existing Work Items.
3. Integrate GitHub in Visual Studio to use the tools that are common between Azure DevOps Git and GitHub through Team Explorer
4. Create Azure Pipelines that incorporate code from repositories on GitHub
Prerequisites – Integrating Github with Azure DevOps
For the walkthroughs that are covered in this article, we require the following prerequisites:
Prerequisite 1: An existing account of Azure DevOps where you are the Administrator. If you don’t have an Azure DevOps account, you may create a free account from https://www.visualstudio.com or https://dev.azure.com.
We also will require a team project on this account. You may create a new one for doing the walkthroughs in this article.
Both, GitHub and Azure DevOps, offer Public or Private projects. Public projects are ones where anyone can participate in development, whereas private projects are accessible only to the team that belongs to the organization and which owns the account.
Since the default GitHub Project is a Public project, we need to ensure that we can create Public projects in Azure DevOps. For doing so, in the organization settings under the Policies, ensure that “Allow Public Projects” policy is enabled. I have created a new public team project named SSGS-EMS.
Figure 1: Allow public projects
Prerequisite 2: An existing account of GitHub where you are administrator. If you don’t have a GitHub account, you may create a free account on from https://www.github.com. We will require a repository that we can connect to, from Azure DevOps. I have an existing repository named SSGS-EMS on my GitHub account.
Prerequisite 3: Visual Studio 2017 onwards any edition of Visual Studio. [Optional]
Connecting Azure Boards with GitHub
Let us first see how do we connect an Azure DevOps account to GitHub account for integrating Azure Boards with GitHub.
Azure Boards is a service that facilitates agile planning and monitoring. It used to be called “Work Item Tracking” service and is used mainly for managing requirements, efforts, tests and bugs.
We need to provide GitHub credentials so that Azure DevOps will use them when necessary to get details of Commits, Pull Requests and Issues from GitHub, and link them with work items which is a part of Azure Boards.
1. Open the Project Settings in the team project on Azure DevOps portal and select “GitHub Connections” under the section of Boards.
Figure 2: Connect GitHub to Azure Boards
2. Click on the button that says “Connect your GitHub account” if you don’t have any existing GitHub connection. If you already have an existing GitHub connection, then click the button that says “New Connection”.
3. It starts a wizard to create connection.
In that wizard, first we are asked to authenticate to GitHub. Then we have to authorize Azure Boards to access repositories under GitHub.
Then select GitHub repositories on which Azure Boards has access permissions to, and finally install the GitHub app (extension) that allows Azure Boards to communicate with GitHub.
I have connected to my newly created repository SSGS-EMS and “training” which contains many of my resources for public use.
Figure 3: Azure Boards to GitHub connection
In this way, we form the connection from Azure Boards (part of Azure DevOps) to GitHub.
Let us now connect to the same repository (SSGS-EMS) from Visual Studio and push some code into it. We will also check how we can link the commit with the work item at that time.
Use GitHub from Visual Studio
1. Open Visual Studio. I have used Visual Studio 2017 that was installed on my demo machine but you may use Visual Studio 2019 also and follow the same steps. If you do not have Visual Studio installed or if you have a version older than 2017, then you can download Visual Studio 2019 Community Edition, free for learning purpose, from https://www.visualstudio.com.
2. In Visual Studio, from Tools – Extensions, search and select the extension for GitHub and install it.
Figure 4: Add GitHub Extension in Visual Studio
3. Now to connect to the GitHub repository, in Team Explorer, click on the Connect button and then from Manage Connection dropdown, click the option of Connect to GitHub.
Authenticate with GitHub credentials for connecting:
Figure 5: Connect from Visual Studio to GitHub
4. Once connected to GitHub, let us clone the repository SSGS-EMS. We will require URL of the repository from GitHub which can be copied from the GitHub page. After entering the URL in the path, make any changes in the local repository folder and click on the Clone button to start the cloning process.
Figure 6: Select and clone GitHub repository
5. Once the repository is cloned, the view in Team Explorer will change as in Figure 7. We will click the New button under the Solutions section to create a new solution in this repository. If a solution already exists on the local machine, we can move it under the folder that is mapped to the local git repository when we cloned the remote repository.
Figure 7: Create new solution and add it to GitHub repository
6. After the solution and the project is created, we can commit and push that to the remote repository.
To do so, we click the Changes tab under the Project section in team explorer, enter a message for commit and then from the dropdown of “Commit”, we accept the option of “Commit and Push”.
In the message, if we provide the text “AB#” and then the work item id in front of that, then this commit is linked to that work item.
In the example that I have shown, the work item id is 10319. That work item is a User Story under the Team Project SSGS-EMS that we had linked earlier to GitHub in the first few steps of this walkthrough.
“AB” in the text stands for “Azure Boards”. The complete text in the example is “AB#10319”. It is a part of the commit message. In addition to this text if we mention “fixes”, “fixed” or “fixing” words in the message, it will also change the status of the work item to “Closed” or “Done”.
Example of such message is “Edited ContactUs.aspx for fixing AB#10319”.
Figure 8: Commit and push to GitHub repository
Linking GitHub commits and issues in the browser
Let us now see another way to link the commits and also the issues on the portal of Azure DevOps.
Let’s explore a case where a commit and push are already done and the message did not have the work item id to link it with that commit. We want to link that commit with a work item, say a User Story against which the code is created.
1. To do so, open the browser and go to the Azure DevOps portal. Open the team project page that we had linked in the initial steps of the last walkthrough. In my example, it is SSGS-EMS team project.
2. Open the work item that we want to link with the commit. Click the Links page and then click Add Link button. From the drop down of Link Type select “GitHub Commit”. This option is available only for team projects that are linked to the GitHub account.
Figure 9: Add link to GitHub commit
3. Now copy the URL of the commit that we want to link from GitHub and paste it into the next dialog box, to provide the details.
Figure 10: Details of GitHub commit while linking it with work item
4. Now we can see the linked commits in the Development section of the page.
Figure 11: Added link from GitHub commit
5. We can also add links to GitHub issues in a similar way.
Figure 12: Add link to GitHub issue and details
6. In addition to viewing those links in the Links and Development pages of the work item, we can also view them on the Kanban board of the project:
Figure 13: GitHub commits and issues appearing On KANBAN Board of Azure Boards
Note: Learn how to use Git in Azure DevOps.
In the next walkthrough, we are going to see how the code in GitHub can be accessed by Azure Pipelines to build it.
Accessing Github Code using Azure Pipelines
By default, Azure Pipelines can access code from Azure Repos, GitHub, GitHub Enterprise, Atlassian BitBucket and SVN etc. For accessing it from outside the boundary of Azure DevOps, we have to provide it with authentication details.
For example, if we want to get code from GitHub, we have to provide either login credentials that can be used as OAuth credentials or Personal Access Token (PAT) that is generated by GitHub. Once either of these are provided, every time code is to be accessed from GitHub, Azure Pipelines will use those credentials. Let us see how we can provide these credentials.
1. On the Get Sources page of the Build Pipeline definition, we will select the option of GitHub. It will ask us to provide GitHub credentials to be used in OAuth or PAT.
Figure 14: Pipeline source authorize Azure DevOps to access code from GitHub
2. On the page that shows details of entity that wants to access our account and the permissions that are sought, click the button to authorize our Azure Pipelines account to access the GitHub account.
Figure 15: OAuth Authorization
3. On the next screen, provide a password to ensure that the permissions are granted.
Figure 16: Password for authorization
4. Finally, we will select one or multiple repositories that can be accessed by Azure Pipelines.
Figure 17: Select source repository
5. Now we can complete the configuration of build pipeline and then Save and Queue the build.
Figure 18: Save and queue
6. We will observe that during the run of the build pipeline, our repository is accessed by the pipeline and the source is retreived and built.
Figure 19: Get source from GitHub during build
This article is a tutorial to use Azure DevOps and GitHub collaboratively.
For those teams, which are using GitHub for public (Open Source) projects and now want to use other DevOps features like CI/CD and Agile product development, Azure DevOps provides excellent services which integrate with their practices on GitHub.
We can integrate Azure Boards service to get commits in GitHub to be linked and viewed. We can also have code under GitHub to be built and deployed using Azure Pipelines.
This article was technically reviewed by Gouri Sohoni.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!