Close

Resolve Merge Conflicts in Azure DevOps

Working with Git can be quite challenging. Especially when you receive merge conflicts. In this case I had branches Development and Master in the remotes/origin repository. If you want to make code changes to these branches, you will have to create a feature branch (in dev.azure.com, from the development branch) first. Via Pull Requests the feature branch is merged into the Development branch and next to the Master branch. On merging Development and Master I received merge conflicts.

  • In Azure DevOps, create a remote hotfix branch from Master.
  • Select the local Development branch from the taskbar of Visual Studio. In Team Explorer, go to the Synchronization tab and click fetch/pull to get the latest version.
  • In Team Explorer, go to the Branches tab. The hotfix branch will be available under remote/origin. If the remote hotfix branch is not available, go to the Synchronization tab again and choose Sync.
  • Create a local hotfix branch in Visual Studio by right-clicking the remote hotfix branch. Choose “New Local Branch From”. The local hotfix branch will automatically be opened in Visual Studio.
  • In Visual Studio, merge the local Development branch into the local hotfix branch. You can perform this action from the Branches tab in Team Explorer. Make sure you are in the local hotfix branch.
  • Resolve the merge conflicts. You can accept the changes from the Development branch (source) as these branch contains the latest changes.
  • Commit changes to the local hotfix branch and Sync the branch to the remote repository.
  • In DevOps merge the hotfix branch into the Master branch. The hotfix branch is automatically removed on Auto Complete. If not, remove the hotfix branch. Now we are ready to merge Development into Master again without merge conflicts.
  • In DevOps, merge the Development branch into Master (via a pull request).

Instead of resolving merge conflicts over and over again, it’s obviously better to resolve the root cause of the problem. In this case the Development branch was created first. The Master branch was only needed at a later stage, more specifically, for the release to Accept and Production. So the Master branch was created from the Development branch and not the other way around. That causes merge conflicts.

The correct approach is to create a Master branch first and then a Development branch per project (for instance: development/project1, development/project2). For the Development branch we can create feature branches to support multiple developers working on the same project. When ready, the feature branches are merged back into the active Development branch. The Development branch is eventually merged into the Master branch again (when we move to Accept testing). Once, we are ready to go live and find a bug after that, we can create a hotfix branch. The hotfix branch is merged back into the Master branch. The Master branch is merged into the active Development branch.