Pull requests are a key feature of GitHub that allow us to propose changes to a codebase. They provide a platform for discussion and review of our proposed changes before they are merged into the codebase. For example, if we've fixed a bug that was detailed in an issue (as discussed in the previous chapter), we can open a pull request to propose our bug fix. Here's a simple explanation:
-
Create a Branch: We start by creating a new branch in our repository. This branch will contain the changes we want to propose.
-
Make Changes: We then make our changes to the code on this new branch. These changes could be anything from fixing a bug to adding a new feature.
-
Open a Pull Request: Once we're happy with our changes, we open a pull request. This is a proposal to merge our changes into the main codebase. In the pull request, we explain our changes and why we think they should be included. Here are the steps to open a pull request:
-
Step 1: Navigate to the repository where we want to open a pull request. The repository link is usually in the format www.github.com/<username>/<repository-name>
.
-
Step 2: Click on the Pull requests
tab.
-
Step 3: Click on the New pull request
button. If we have recently pushed a new branch to the repository, GitHub will automatically suggest opening a pull request for that branch. It will look something like this:
In this case, we can click on the Compare & pull request
button to proceed. And skip to Step 5.
-
Step 4: Select the branch that contains our changes.
-
Step 5: Fill in the pull request title and description.
-
Step 6: Click on the Create pull request
button.
-
Review and Discussion: Other developers can now review our proposed changes and leave comments. This is a chance for us to get feedback and make any necessary adjustments.
-
Merge: If our changes are approved, they are merged into the main codebase. We will learn more about merging in the next chapter.