Git & GitHub ยท Chapter 29 of 42

GitHub Pull Requests

A pull request (PR) is a request on GitHub to merge changes from one branch (or fork) into another, usually main. PRs are the standard way teams review and discuss code before it's merged.

A pull request shows the diff of proposed changes, allows comments on specific lines, supports automated checks, and requires approval before merging in most team workflows.

Syntax
git push -u origin feature-branch
# then open a PR on GitHub

Opening a pull request

Push your branch to GitHub, then click 'Compare & pull request' on the repository page. Add a title and description explaining what the change does and why.

Reviewing and merging

Teammates can comment, request changes, or approve the PR. Once approved and any checks pass, click 'Merge pull request' to bring the changes into the target branch.

Example 1 (bash)
git push -u origin feature-login
Output
Branch 'feature-login' set up to track remote branch 'feature-login' from 'origin'.

Pushes the feature branch to GitHub so a pull request can be opened from it.

Example 2 (bash)
git fetch origin
git switch main
git pull
Output
Fast-forward
 app.js | 12 +++++++++---

After a PR is merged on GitHub, pulling main locally brings in the newly merged changes.

Key points

  • A pull request proposes merging one branch into another on GitHub.
  • PRs allow code review with comments before merging.
  • Automated checks (like tests) can run automatically on a PR.
  • Merging a PR on GitHub updates the target branch remotely.
๐Ÿ’ก Note: Writing a clear PR description helps reviewers understand your changes faster and results in quicker approvals.

๐Ÿ“ Quick Quiz

1. What is a pull request?

2. What can teammates do on a pull request?

3. What often runs automatically on a pull request?