A pull request is a request for merging a source branch to a base branch. The base branch is the branch where the reviewed code resides. In this case, our base branch is master. Pull requests are generally useful for developers to get their code peer reviewed before they merge it with the fair version of the code. The reviewer generally checks the quality of the code, whether best practices are being followed, and whether coding standards are appropriate. If the reviewer is unhappy, they might want to flag certain sections of the changes and request modifications. There are normally multiple cycles of reviews, changes, and re-reviews. Once the reviewer is happy with the changes, they can approve the pull request, and the requester can merge the code. Let’s take a look at this process:
- Let’s try to raise a pull request for merging our code from the feature/feature1 branch to the master branch. To do so, go to your GitHub repo, select Pull requests, and click on the New pull request button, as shown in the following screenshot:
Figure 2.7 – New pull request
- Keep base set to master and, in the compare dropdown, select feature/feature1:
Figure 2.8 – Comparing changes
- As you can see, it shows you all the changes we’ve made on the feature/feature1 branch. Click on the Create pull request button to create the pull request. On the next page, stick to the defaults and click on the Create pull request button:
Figure 2.9 – Pull request created
- As you can see, the pull request was created successfully. Here, you can assign a reviewer and get the code reviewed. Once the reviewer approves the code, you can merge the code to the master branch. For now, let’s click on the Merge pull request button, followed by the Confirm merge button, which should merge the pull request.
- Now, check if the master branch shows the changes within GitHub. If it does, switch to the master branch and pull the changes into your local repository. You should see the changes in your local repository as well.
I leave this to you as an exercise.
This was a crash course on Git to help you get started. Now, let’s move on and understand GitOps, which uses Git as a single source of truth to spin up virtually anything within your application and infrastructure.