Basic Git Series: Creating a Pull Request on GitHub

Adam Sturge | Aug 22, 2023 min read

Overview

Pull requests (PRs) are a way to propose changes to a repository. They allow team members to review code before it’s merged into the main branch.

Steps

  1. Push your branch to GitHub:
git push -u origin your-branch-name
  1. Navigate to the repository on GitHub
  2. Click on “Pull requests” tab
  3. Click the “New pull request” button
  4. Select the base branch (where you want to merge) and your compare branch
  5. Add a title and description for your PR
  6. Click “Create pull request”

Creating a Pull Request Directly on GitHub

You can also create a pull request entirely through GitHub’s web interface:

  1. Navigate to the repository on GitHub
  2. Make changes and commit them to a new branch:
    • Click the pencil icon on a file to edit
    • Make your changes
    • At the bottom, select “Create a new branch and start a pull request”
    • Provide a branch name
    • Click “Propose changes”
  3. On the next screen, add a description for your PR
  4. Click “Create pull request”

This method is great for small changes when you don’t want to set up a local development environment.

Common Issues

  • Merge conflicts: If your branch conflicts with the base branch, you’ll need to resolve these before merging
  • Failed CI checks: Make sure all automated tests pass before requesting review
  • Outdated branch: If the base branch has moved forward, update your branch:
    git checkout your-branch-name
    git pull origin main  # Or whichever is your base branch
    git push
    

Additional Notes

  • Add relevant reviewers to get feedback
  • Use labels to categorize your PR (bug fix, enhancement, etc.)
  • Link related issues in your PR description with keywords like “Fixes #123” or “Closes #456”
  • Draft PRs (mark as “Draft”) are useful when you want early feedback but the work isn’t complete