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.
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.

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.
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.

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.
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

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.
Once the PR is created, you (usually the reviewer) can approve the PR as shown below.

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

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.

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.
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