Lesson 42 of 60 – Pull Requests
70%

Pull Requests

A Pull Request (PR) is a feature used to propose changes from one branch or repository to another. Pull requests are commonly used on GitHub for code review, discussion, testing, and merging changes.

Note: A pull request is not the same as git pull. A pull request is a collaboration feature on GitHub, while git pull is a Git command used to retrieve and integrate changes from a remote repository.

1. What is a Pull Request?

A pull request is a request to review and potentially merge changes from one branch into another.

Feature Branch
      ↓
Pull Request
      ↓
Review
      ↓
Merge
      ↓
Target Branch

2. Why Use Pull Requests?

Pull requests provide a structured way to review and discuss code before it is merged.

  • Review code
  • Discuss changes
  • Run automated checks
  • Track development work
  • Collaborate with developers
  • Propose changes safely

3. Pull Request vs Git Pull

Pull Request git pull
GitHub collaboration feature Git command
Used to propose and review changes Retrieves and integrates remote changes
Created on a Git hosting platform Executed in a local Git repository

4. Source Branch

The source branch contains the changes being proposed.

feature-login
     ↓
Pull Request

The source branch may exist in the same repository or, in a fork workflow, in a different repository.

5. Target Branch

The target branch is the branch into which the changes are proposed to be integrated.

feature-login
      ↓
     PR
      ↓
main

The target branch is selected when creating the pull request.

6. Creating a Feature Branch

A common workflow starts by creating a feature branch.

git switch main
git pull

git switch -c feature-login

The feature can then be developed independently from the main branch.

7. Making Changes

After creating a feature branch, modify the project files as needed.

git status

git add .

git commit -m "Add login feature"

The changes should be committed before pushing the branch.

8. Push the Feature Branch

Push the branch to the remote repository:

git push -u origin feature-login

After pushing, the branch can be used to create a pull request.

9. Creating a Pull Request

After pushing your branch, open the repository on GitHub and create a pull request from the source branch to the desired target branch.

feature-login
      ↓
Create Pull Request
      ↓
main

10. Pull Request Title

A pull request should have a clear title describing the proposed change.

Add user login functionality

A good title makes the purpose of the pull request easy to understand.

11. Pull Request Description

The description explains what the pull request changes and why the changes were made.

## What changed?

- Added login form
- Added validation
- Added session handling

## Testing

- Tested valid login
- Tested invalid password

12. Pull Request Reviewers

Repositories can use reviewers to examine proposed changes. Reviewers can inspect the code and provide comments or request changes.

Developer
    ↓
Pull Request
    ↓
Reviewer
    ↓
Comments / Approval / Changes

13. Code Review in Pull Requests

Code review allows developers to examine the proposed changes before they are merged.

Reviewers may check:

  • Code quality
  • Logic
  • Security
  • Performance
  • Testing
  • Project conventions

14. Pull Request Comments

Reviewers and contributors can discuss the proposed changes using comments.

Reviewer:
Could this validation be moved into
a separate function?

Developer:
Yes, I will refactor it.

15. Requesting Changes

A reviewer can request changes when the proposed code needs modification before it can be accepted according to the project's review process.

Pull Request
     ↓
Code Review
     ↓
Changes Requested
     ↓
Developer Updates Code
     ↓
Review Again

16. Updating a Pull Request

A pull request is normally updated automatically when new commits are pushed to its source branch.

git add .
git commit -m "Fix review comments"
git push

The new commit becomes part of the existing pull request.

17. Pull Request Checks

Repositories can use automated checks to validate pull requests.

Examples include:

  • Automated tests
  • Build checks
  • Linting
  • Security checks
  • Code quality checks

The exact checks depend on the repository configuration.

18. Pull Request Merge

After the required review and checks are completed, an authorized person can merge the pull request according to the repository's settings and workflow.

Feature Branch
      ↓
Pull Request
      ↓
Review
      ↓
Checks
      ↓
Merge
      ↓
Target Branch

19. Merge Options

GitHub repositories can be configured with different methods for integrating pull requests.

Common approaches include:

  • Merge commit
  • Squash and merge
  • Rebase and merge

Which method is available depends on repository settings and branch rules.

20. Pull Request and Issues

Pull requests can be associated with GitHub Issues to connect development work with a reported bug or requested feature.

Issue #25
    ↓
Feature Branch
    ↓
Pull Request
    ↓
Code Review
    ↓
Merge

This creates a connection between the problem and the code that addresses it.

21. Closing an Issue from a Pull Request

GitHub supports keywords that can link a pull request to an issue and automatically close the issue when the pull request is merged.

Fixes #25

The exact result depends on the repository and the way the pull request is merged.

22. Pull Requests from Forks

In an open-source workflow, contributors can create a fork, make changes in their fork, and then submit a pull request to the original repository.

Original Repository
       ↓
      Fork
       ↓
Feature Branch
       ↓
Pull Request
       ↓
Original Repository

23. Pull Request Drafts

A draft pull request can be used when the work is still in progress and is not yet ready for final review or merging.

Work in Progress
      ↓
Draft Pull Request
      ↓
Continue Development
      ↓
Ready for Review

24. Pull Request Labels

Labels can help organize pull requests.

Examples include:

  • feature
  • bug
  • documentation
  • enhancement
  • work in progress

The available labels depend on the repository.

25. Good Pull Request Practices

  • Keep the pull request focused.
  • Use a clear title.
  • Explain the changes.
  • Link related issues.
  • Test your changes before submitting.
  • Keep commits understandable.
  • Respond to review comments.
  • Keep the branch updated when necessary.

26. Common Pull Request Mistakes

  • Creating very large unrelated changes in one PR.
  • Using an unclear title.
  • Not explaining the changes.
  • Not testing the code.
  • Ignoring review comments.
  • Committing sensitive information.
  • Targeting the wrong branch.
  • Leaving unresolved conflicts.

27. Example Pull Request

Title:
Add student attendance report

Description:

## Changes
- Added monthly attendance report
- Added attendance percentage
- Added date filter

## Testing
- Tested monthly filter
- Tested student search

Related Issue:
Fixes #25

28. Complete Pull Request Workflow

git switch main
git pull

git switch -c feature-report

# Make changes

git add .
git commit -m "Add attendance report"

git push -u origin feature-report

        ↓

Create Pull Request
        ↓
Code Review
        ↓
Automated Checks
        ↓
Fix Requested Changes
        ↓
Review Again
        ↓
Merge Pull Request

29. Pull Request Checklist

  • Choose the correct source branch.
  • Choose the correct target branch.
  • Write a clear title.
  • Explain what changed.
  • Link related issues when appropriate.
  • Test the changes.
  • Review your own code first.
  • Respond to reviewer comments.
  • Resolve conflicts when necessary.
  • Verify required checks before merging.

30. Summary of Pull Requests

A pull request provides a structured way to propose, discuss, review, test, and potentially merge changes into another branch.

Feature Branch
      ↓
Push Changes
      ↓
Pull Request
      ↓
Review
      ↓
Automated Checks
      ↓
Changes if Needed
      ↓
Approval
      ↓
Merge

Pull requests are an important part of collaborative Git and GitHub workflows because they provide a place for code review and discussion before changes are integrated.

📌 Key Points

  • A pull request proposes changes from one branch or repository to another.
  • Pull requests are commonly used for code review and collaboration.
  • The source branch contains the proposed changes.
  • The target branch receives the proposed changes after integration.
  • A pull request is different from the git pull command.
  • Pull requests can contain titles, descriptions, comments, and reviews.
  • Reviewers can request changes before integration.
  • New commits pushed to the source branch can update an existing pull request.
  • Automated checks can test pull request changes.
  • Pull requests can be associated with GitHub Issues.
  • Fork-based projects commonly use pull requests for external contributions.
  • GitHub repositories can support different pull request merge methods.

🧠 Quick Quiz

Question: What is the main purpose of a Pull Request?