Git & GitHub
/Beginner
Pull Requests (PR)
Definition
A mechanism in GitHub that notifies team members that a feature is completed. It provides a dedicated web page for developers to discuss, review, and approve the proposed code changes before they are merged into the main branch.
Explain Like I'm New
In Open Source, you can't just shove your code into someone else's project. You have to politely ask them: 'Hey, I wrote this code to fix your bug. Could you please PULL my code and merge it?'. Thus, a Pull Request.
Real World Example
You finish building a new Login page on your `feature-login` branch. You don't merge it yourself. You open a PR on GitHub. Your senior developer reads the PR, spots a security flaw, leaves a comment, you fix it, and THEN it gets merged.
Common Use Cases
- •Code review
- •Gatekeeping the main branch
- •Discussing features
Terminal Output
bash / terminal
/*
The standard PR Workflow:
1. Developer creates branch locally: `git checkout -b feature-xyz`
2. Developer writes code and commits it.
3. Developer pushes branch to GitHub: `git push origin feature-xyz`
4. Developer logs into GitHub.com and clicks 'Compare & pull request'.
5. Reviewers look at the code diffs on the website.
6. Reviewers approve it.
7. Someone clicks the green 'Merge pull request' button.
*/
Interview Questions
basic
- Is a Pull Request a native Git feature or a GitHub feature?
intermediate
- What is a 'Merge Request'?