Lesson 6
Pull Requests
In this lesson, we will explore the concept of pull requests (PRs), which are a key feature of GitHub for collaborating on projects and contributing to open-source software. You will learn how to create, review, and approve pull requests, as well as how to resolve conflicts that may arise during the process.
Objectives
- Understand the purpose of pull requests
- Learn how to create a pull request
- Learn how to review and approve pull requests
- Understand how to resolve conflicts in pull requests
Creating a pull request
A pull request is a way to propose changes to a repository. It allows you to submit your changes for review and approval by the repository owner or collaborators. To create a pull request, first push your changes to a branch in your forked repository, then click the New Pull Request button on the original repository page on GitHub.
Reviewing and approving pull requests
When a pull request is submitted, the repository owner or collaborators can review the changes and provide feedback. They can either approve the pull request, request changes, or leave comments for further discussion. To approve a pull request, click the Review changes button, select Approve, and then click Submit review.
Merging pull requests
Once a pull request has been approved, it can be merged into the target branch. This incorporates the proposed changes into the main codebase. To merge a pull request, click the Merge pull request button, then confirm the merge by clicking Confirm merge.
Resolving pull request conflicts
Sometimes, conflicts may arise when merging a pull request due to changes in the target branch that are incompatible with the proposed changes. In such cases, you will need to resolve the conflicts manually by editing the conflicting files, committing the changes, and pushing them to the branch associated with the pull request.
Exercises
Create a pull request in your own repository
- Create a new branch in your own repository and make some changes to the code
- Push the changes to the new branch, then create a pull request to propose merging the changes into the main branch
- Review the changes and approve the pull request.
Resolve conflicts in a pull request
- Intentionally create a conflict in your pull request by making conflicting changes in the main branch and the new branch
- Attempt to merge the pull request
- Resolve the conflicts manually by editing the conflicting files
- Commit the changes, and push them to the branch associated with the pull request.