Implement feature branching in Azure DevOps

Introduction

This post provides an example of how feature branching can be used. Specially, how it can be used by a developer to apply their work item changes to a develop branch (following the Gitflow pattern). The example will discuss:

  • Creating a user story (work item) branch based off the develop branch
  • Implementing the changes within that branch
  • Raising a pull request for the changes, which, after being approved, is merged into the develop branch

The tools used in this example are

  • Azure DevOps
  • Azure Repos Git
  • Visual Studio 2022

Example

1.) Clone the repository

Figure 1

Referring to Figure 1, the ‘products-contoso’ repository contains a develop branch. Referring to Figure 2, a local develop branch has been created from this branch. The contents of the local develop branch can be viewed on the local file system (Figure 3)

(Note: to navigate to the screen shown in Figure 2, select ‘Git’ on the menu bar, then ‘Manage Branches’).

Figure 2
Figure 3

2.) Create a temporary local user story branch

Since it was just cloned, the local develop branch already contains the latest changes. Thus, a new user story branch ‘story/48286’ can be immediately created off the develop branch, without requiring a fetch/pull (Figure 4)

Figure 4

3.) Implement the required changes in the user story branch

Figure 5

The changes e.g. updating the NonComplianceForm.ts file (Figure 5) are stored in the file system (Figure 3).

(Note: if the developer was to now try and checkout another local branch, the changes in the file system could potentially be lost. So, the following options are presented to the developer (Figure 6).)

Figure 6

4.) Commit changes in the user story branch

The changes to the NonComplianceForm.ts file are committed locally and displayed in ‘Outgoing’ (Figure 7)

Figure 7

5.) Push changes in the user story branch

Pushing the commit (Figure 7) results in the user story branch ‘story/48286’ being created in the Azure DevOps repository ‘products-contoso’ (Figure 8)

Figure 8

6.) Create pull request

The changes in user story branch ‘story/48286’ are now ready to be placed in a pull request. Once the pull request is complete, the user story branch is merged into the develop branch within Azure DevOps repos ‘products-contoso’

7.) Further changes

Consider the situation where, in a few days time, another change needs to be made to the user story. The developer could make the changes in the existing user story branch. However, there could be merge issues when the user story branch is updated with the latest changes from the develop branch. If this is the case, it could easier to abort the merge and create a new user story branch containing the latest changes.

Further reading

Azure DevOps blog posts

References

https://learn.microsoft.com/en-us/azure/devops/boards/work-items/about-work-items?view=azure-devops&tabs=agile-process

https://learn.microsoft.com/en-us/azure/devops/repos/git/git-branching-guidance?view=azure-devops

https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow