Git Notes
Master GitHub Pull Requests for proposing changes, requesting reviews, managing feedback, and merging code. Learn PR best practices and workflows.
Pull Requests (PRs) are GitHub's mechanism for proposing changes and requesting code review before merging into a target branch. They are central to collaborative development workflows.
Creating a Pull Request
From the Command Line
# Create and push a feature branch
git checkout -b feature/add-search
# ... make changes ...
git add .
git commit -m "feat: add search functionality"
git push origin feature/add-searchremote: Create a pull request for 'feature/add-search' on GitHub by visiting: remote: https://github.com/user/repo/pull/new/feature/add-search
On GitHub
- Go to your repository
- Click "Pull requests" → "New pull request"
- Select base branch (e.g.,
main) and compare branch (e.g.,feature/add-search) - Fill in title and description
- Click "Create pull request"
PR Description Template
PR States and Actions
| State | Meaning |
|---|---|
| Open | Awaiting review or discussion |
| Draft | Work in progress, not ready for review |
| Review Required | Waiting for reviewer approval |
| Changes Requested | Reviewer asked for modifications |
| Approved | Reviewer approved the changes |
| Merged | Changes integrated into target branch |
| Closed | PR rejected or abandoned |
Draft Pull Requests
Open a PR early to get feedback on approach:
# Push your WIP branch
git push origin feature/new-approach
# On GitHub: Create PR → click "Create draft pull request"Convert to ready when done: "Ready for review" button.
Merge Options
Merge Commit (Default)
Squash and Merge
Combines all PR commits into one:
Rebase and Merge
Replays commits on top of base:
Best Practices
- Keep PRs small — Under 400 lines of changes ideally
- One concern per PR — Don't mix features with refactoring
- Write descriptive titles — "feat: add user search with Elasticsearch" not "update code"
- Use draft PRs for WIP — Get early feedback on direction
- Respond to reviews promptly — Keep the feedback loop short
- Test before requesting review — Don't waste reviewers' time
Interview Questions
- What is a Pull Request?
A Pull Request is a proposal to merge changes from one branch into another. It provides a forum for code review, discussion, CI checks, and approval before changes are integrated.
- What is the difference between the three merge options (merge, squash, rebase)?
Merge creates a merge commit preserving all history. Squash combines all PR commits into one clean commit. Rebase replays each commit on top of the base branch without a merge commit.
- When would you use a draft Pull Request?
When your work is in progress and you want early feedback on your approach, architectural decisions, or implementation direction without signaling that the code is ready for final review.
- How do you link a PR to an issue?
Use keywords in the PR description: "Closes #123", "Fixes #456", or "Resolves #789". When the PR is merged, the referenced issues are automatically closed.
- What makes a PR easy to review?
Small size (under 400 lines), clear description, focused scope (one feature/fix), tests included, screenshots for UI changes, and self-reviewed before requesting others.
Common Pull Request Mistakes to Avoid
Even experienced developers make PR mistakes that slow down the review process. Here are common pitfalls and how to avoid them:
1. Giant PRs (1000+ lines) Large PRs are exhausting to review and often get rubber-stamped without careful examination. Break large features into logical, independently mergeable chunks. A feature flag can hide incomplete functionality while allowing incremental merges.
2. No context in the description Reviewers shouldn't need to read the issue, Slack conversation, and design doc to understand your PR. Include the "why" in the description — what problem does this solve, what approach did you take, and what alternatives did you consider?
3. Mixing unrelated changes A PR that adds a feature AND refactors the database layer AND updates dependencies is three PRs disguised as one. Each concern should be a separate PR for clean history and easier review.
4. Not self-reviewing before requesting review Always review your own diff before adding reviewers. You'll catch typos, debug logs, commented-out code, and formatting issues that waste reviewers' time.
Pull Request Etiquette for Reviewers
Being a good reviewer is as important as writing good PRs:
- Be constructive: "Consider using a map here for O(1) lookup" is better than "This is slow"
- Distinguish blockers from suggestions: Use prefixes like "nit:", "suggestion:", or "blocking:" to clarify severity
- Approve with comments: If your feedback is minor (typos, style preferences), approve the PR with comments rather than requesting changes
- Review promptly: Aim to review within 24 hours. Stale PRs lead to merge conflicts and context loss
- Ask questions: "What happens if this list is empty?" is a gentle way to surface a potential bug
Automation and CI/CD Integration
Modern PR workflows integrate with CI/CD pipelines. When a PR is opened, automated checks typically include:
- Unit tests: Verify existing functionality isn't broken
- Linting: Enforce code style consistency
- Type checking: Catch type errors early
- Security scanning: Detect vulnerable dependencies
- Coverage reports: Ensure new code has adequate tests
- Preview deployments: Generate a live preview URL for UI changes
These automated checks reduce reviewer burden and catch mechanical issues before human review begins.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Pull Requests - Propose and Review Code Changes.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, collaboration, pull, requests, pull requests - propose and review code changes
Related Git & GitHub Topics