Pull Requests & Collaboration
What is a Pull Request?
A Pull Request (PR) is a request to merge your branch into another branch. It's not a git feature — it's a GitHub feature built on top of git. PRs give your team a structured way to review, discuss, and approve code before it lands in main.
The Full Feature Branch Workflow
-
1Create a branch:
git switch -c feature/add-login -
2Make commits on your branch as normal
-
3Push the branch:
git push origin feature/add-login -
4Open a PR on GitHub — click "Compare & pull request" or go to Pull Requests → New
-
5Request reviewers, respond to comments, push additional commits if needed
-
6Merge the PR once approved — GitHub merges your branch into main
-
7Clean up: delete the branch on GitHub, then locally:
git branch -d feature/add-login
Writing a Good PR Description
A good PR description helps reviewers understand what changed and why. Include:
- What this PR does (one sentence)
- Why it's needed (the problem being solved)
- How to test the change
- Screenshots for UI changes
- Links to relevant issues (
Closes #42)
Code Review Etiquette
As a reviewer:
- Be specific — quote the exact line you're commenting on
- Distinguish blocking ("this must change") from suggestions ("you could also...")
- Approve when satisfied — don't leave people hanging
As the PR author:
- Respond to every comment
- Mark threads as resolved after fixing
- Don't take feedback personally — it's about the code
Merge Strategies
GitHub offers three ways to merge a PR:
- Merge commit — preserves all history, adds a merge commit
- Squash and merge — combines all commits into one (clean history)
- Rebase and merge — replays commits on top of main (linear history)
Most teams use Squash and merge so main has one commit per feature.
Draft PRs: Open a PR as a "Draft" while you're still working to signal it's not ready for review. Convert to ready when done.
Protecting Your Main Branch
In GitHub → Settings → Branches → Add rule, you can require:
- At least 1 review approval before merging
- All CI checks to pass
- No direct pushes to main
Final Challenges
Create and switch to a feature branch:
git switch -c feature/my-pr
Make a commit on that branch
Push the branch:
git push origin feature/my-pr
Switch back to main and merge:
git switch main && git merge feature/my-pr
student@git-mastery: ~/my-project (main)