Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Git & GitHub - GitHub Pull Requests

How to create and manage pull requests on GitHub

Pull requests are a core feature of GitHub that facilitate collaboration by allowing developers to propose changes, review code, and merge updates into the main codebase. This guide explains how to create and manage pull requests on GitHub.

Key Points:

  • Pull requests allow you to propose, discuss, and review changes before merging them into the main branch.
  • Effective use of pull requests enhances code quality and collaboration.
  • GitHub provides tools for reviewing, commenting, and approving pull requests.

Creating a Pull Request

Step 1: Create a Branch

First, create a new branch for your changes:


# Create a new branch
$ git checkout -b feature-branch

# Make changes and commit them
$ git add .
$ git commit -m "Add new feature"
                

Step 2: Push the Branch to GitHub

Push your branch to the GitHub repository:


# Push the branch to GitHub
$ git push origin feature-branch
                

Step 3: Open a Pull Request

Navigate to your repository on GitHub, and you'll see a prompt to open a pull request for the recently pushed branch. Click "Compare & pull request" to start creating the pull request.

Open Pull Request

Fill out the pull request form with the following details:

  • Title: A brief summary of the changes.
  • Description: A detailed description of the changes, why they are needed, and any other relevant information.

Once you've filled out the form, click "Create pull request" to submit it.

Reviewing and Commenting on Pull Requests

Team members can review the pull request by navigating to the "Pull requests" tab in the repository and selecting the pull request. They can add comments, suggest changes, and approve the pull request.

Review Pull Request
  • Comment: Leave feedback on specific lines of code or the pull request as a whole.
  • Request changes: Ask the author to make changes before merging.
  • Approve: Approve the pull request if the changes are satisfactory.

Merging a Pull Request

Once the pull request has been reviewed and approved, it can be merged into the main branch. To merge a pull request:


# Click the "Merge pull request" button
# Confirm the merge by clicking "Confirm merge"
                

After merging, you can delete the branch to keep the repository clean:


# Delete the branch from GitHub
$ git push origin --delete feature-branch

# Delete the branch locally
$ git branch -d feature-branch
                

Closing a Pull Request

If a pull request is no longer needed, you can close it without merging. To close a pull request, navigate to the pull request and click the "Close pull request" button.

Close Pull Request

Summary

This guide covered how to create and manage pull requests on GitHub, including creating a branch, pushing changes, opening a pull request, reviewing and commenting, merging, and closing pull requests. Using pull requests effectively enhances collaboration and code quality in your projects.