To add reviewers to check and approve your code prior to merging, your next step is to create a pull request. In addition to a place for code review, a pull request shows a comparison of your changes against the original repository (also known as a diff) and provides an easy way to merge code when ready.
Step 1. Create the pull request
You need a branch to create a pull request. Good thing you created a branch in the previous section of this tutorial.
From your repository, click + in the global (leftmost) sidebar. Then, click Create a pull request under Get to work. Bitbucket displays the request form. Make sure that you are in a repository before you click + in the global sidebar.
- Complete the form:
- You've already got an automatic Title, your last commit message.
- Add a Description if you'd like.
(Optional - adding a reviewer) If you need someone to review or approve your code prior to merging, add them in the Reviewers field. You can see that we have added a reviewer named Breezy Cloud to the example pull request below.
In order to add a reviewer to a pull request, you must first grant the user access to your repository by adding them to a group. For more information and detailed steps, refer to the following: Grant repository access to users and groups. Note: You can always create the pull request and then add reviewers later.
When you're done, the form will look something like this:
3. Click Create pull request.
Bitbucket opens the pull request, and if you added a reviewer, they will receive an email notification with details about the pull request for them to review.
Step 2. Merge your pull request
Not so fast! You may have noticed the Merge button at the top. Before you click it, you need to wait for an approval of your changes. In addition to the email notification your teammates receive, they'll also see the pull request appear under Pull requests to review on the Your work dashboard.
From the pull request, the reviewer can view the diff and add comments to start a discussion before clicking the Approve button.
When someone approves your pull request, you'll get an email notification. Once you've got the approvals you need (in this case just one!), you can merge. From the pull request, click Merge. And that's it! If you want to see what it looks like when your branch merges with the main branch, click Commits to see the commit tree.