Pull Requests
A pull request (PR) is a GitHub feature that lets you propose merging one branch into another. It gives collaborators a chance to review your changes, leave comments, and approve or reject them before they land on main.
The PR Flow
Open a Pull Request
Make sure you have pushed your feature-greeting branch from the Branching lesson.
- Go to your repo on GitHub.
- GitHub shows a banner: "feature-greeting had recent pushes" with a "Compare & pull request" button. Click it.
- Review the title (auto-filled from your last commit message) and description.
- Write a short description of what the branch does and why.
- Click Create pull request.
Tour the PR Interface
Conversation tab — the main thread. Reviewers leave comments here. You can reply and have a discussion. GitHub shows automatic events (commits pushed, reviews, merge).
Commits tab — lists every commit included in the PR. If you push more commits while the PR is open, they appear here automatically.
Files changed tab — the full diff. Green lines are additions, red lines are deletions. You can leave inline comments on any line by clicking the + icon that appears on hover.
Self-Review Your Diff
Before asking anyone to review, read Files changed yourself. Ask:
- Did I include only the changes this PR is supposed to contain?
- Are there debug lines, commented-out code, or personal notes I forgot to remove?
- Does the commit history tell a clear story?
This habit catches most mistakes before they become review feedback.
Merge the PR
Click Merge pull request → Confirm merge.
GitHub offers three merge strategies:
- Create a merge commit — preserves all branch commits and adds a merge commit. Use for features.
- Squash and merge — combines all branch commits into one commit on main. Good for noisy branches.
- Rebase and merge — replays branch commits on top of main with no merge commit. Keeps history linear.
For personal projects, any strategy is fine. Teams usually settle on one standard. Use "Squash and merge" if your branch has lots of "WIP" commits you do not want cluttering main.
Pull Merged Changes Locally
After merging on GitHub, your local main is behind. Bring it up to date:
git switch main
git pull
git pull downloads the new commits from GitHub and fast-forwards your local main.
Delete the Merged Branch
After merging, the branch is no longer needed.
On GitHub: The PR page shows a "Delete branch" button after a merge. Click it.
Locally:
git branch -d feature-greeting
-d (lowercase) is safe — it refuses to delete an unmerged branch. Use -D only if you are sure you want to discard unmerged work.
Capstone: Full PR Flow
Do the whole loop from scratch:
git switch -c feature-about- Create a file
about.txtwith one sentence. - Commit and push.
- Open a PR on GitHub.
- Review the diff in "Files changed."
- Merge.
git switch main && git pullgit branch -d feature-about
Summary
| Action | Where |
|---|---|
| Open PR | GitHub → "Compare & pull request" |
| Review diff | PR → "Files changed" tab |
| Merge | PR → "Merge pull request" |
| Pull merged commits locally | git switch main && git pull |
| Delete merged branch locally | git branch -d <name> |