Azure DevOps – Tips and Tricks – 13 – How to merge two branches using Pull Request approval workflow

In this article, we are going to learn how to merge a feature branch to the main using a Pull Request.

Introduction

When you work in a team, every developer would get some tasks. And for every task that you get, It’s a good practice to create a feature branch. This feature branch contains all the changes for that task.

Advertisements

As per your personal opinion you would like to divide your task into three sub-tasks. And so you would decide to commit based on those sub tasks. Let’s say for example we have a task called Task1, You have divided the task into three logical sub tasks. Now you plan to do three commits, one for each sub task. So, your branch called Task1 would have 3 commits.

Below is the screenshot of the above described scenario.

Azure DevOps – Tips and Tricks – 13 – How to merge two branches using Pull Request approval workflow – Task1 History

After implementing the code for the Task1, you have decided to promote your changes from your future branch Task1 to the main branch, so that, others can start using it.

Advertisements

In order to promote the changes, you need to raise a Pull Request (PR) from the Task1 to Main branch.

Below is the current state before raising the Pull Request.

Azure DevOps – Tips and Tricks – 13 – How to merge two branches using Pull Request approval workflow – Branches

As shown in the above screenshot, the branch named Task1 (in feature folder) is ahead of main branch by 3 commits which could be seen in the history tab of the Task1 as shown below.

Advertisements

Pull Request workflow

Let’s now raise a Pull Request by navigating to the Pull Request page (Repos/Pull Requests), In the Pull Requests page, click on the New Pull Request button which opens up the below form

Azure DevOps – Tips and Tricks – 13 – How to merge two branches using Pull Request approval workflow – Pull Request

Once you choose the source and target branch, provide the Title and Description and also select either your peer or your lead as a Reviewer then click on the Create button.

Advertisements

Once the PR is created, you (usually the reviewer) can approve the PR as shown below.

Azure DevOps – Tips and Tricks – 13 – How to merge two branches using Pull Request approval workflow – Approve

Once you click on the Complete button, a popup comes up where you can click on Complete Merge a shown below

Azure DevOps – Tips and Tricks – 13 – How to merge two branches using Pull Request approval workflow – Complete Merge

In the above step, we did Merge (no fast forward) to complete the merge. In the next tip, Azure DevOps – Tips and Tricks – 14 –  How to combine multiple commits into a Single commit using squash merge, we learn how to squash multiple commits into one commit to main a clean history.

Navigate to the main branch’s history and view all the three commits that were made to Task1 as shown below.

Azure DevOps – Tips and Tricks – 13 – How to merge two branches using Pull Request approval workflow – Main history

Note: In this article. I was the only one person. So, I was the owner of the Pull request as well as the approver of the pull request. However, when you work in real time project, you will have to pick your lead as a reviewer. If everything is good, they can approve it. And if they don’t like your code, they can provide you feedback or even they reject the PR.

Advertisements

Summary:

In this article, we created a feature branch called Task1, made few commits, raised a PR and then approved it and also reviewed the history of the main branch which also includes the commits done to the Task1 feature branch.

Do you like this article? If you want to get more updates about these kind of articles, you can join my Learning Groups

WhatsApp

Telegram

Advertisements
Advertisements

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s