GitHub Issues, Pull Requests & Code Review Best Practices
In this tutorial, you'll learn about GitHub Issues, Pull Requests & Code Review Best Practices. We cover key concepts, practical examples, and best practices.
GitHub Issues and Pull Requests form the core of project management and code review, integrating with automation and CI/CD pipelines for team collaboration.
In this tutorial, you'll learn how to use GitHub Issues and Pull Requests effectively for project management and code review. Issues track bugs, features, and tasks, while pull requests enable structured code review before merging. By the end, you'll set up issue templates, create PR workflows, and conduct efficient code reviews.
flowchart LR
A[Create Issue] --> B[Label & Assign]
B --> C[Create Branch]
C --> D[Work & Commit]
D --> E[Open Pull Request]
E --> F[Request Review]
F --> G{Approved?}
G -->|No| H[Address Feedback]
H --> F
G -->|Yes| I[Merge PR]
I --> J[Close Issue]
GitHub Issues: Tracking Work
Issues are the building blocks of GitHub project management. Each issue can have labels, assignees, milestones, and linked pull requests.
Create a well-structured issue:
## Bug Report: Login form crashes on empty email
**Description**
When the email field is left empty and the user clicks Submit, the app crashes with a TypeError instead of showing a validation error.
**Steps to Reproduce**
1. Go to /login
2. Leave email field empty
3. Click Submit
4. See white screen / crash
**Expected Behavior**
A validation message: "Email is required"
**Environment**
- Browser: Chrome 120
- OS: macOS 14.2
- App version: 2.1.0
Issue Templates
Create templates in .github/ISSUE_TEMPLATE/:
# .github/ISSUE_TEMPLATE/bug_report.yml
name: Bug Report
description: Report a bug to help us improve
title: "[BUG]: "
labels: ["bug"]
body:
- type: textarea
id: description
attributes:
label: Description
description: What happened?
validations:
required: true
- type: textarea
id: steps
attributes:
label: Steps to Reproduce
placeholder: 1. Go to... 2. Click... 3. See error
validations:
required: true
Pull Requests: Structured Review
Open a pull request with a clear description:
## Description
Adds user authentication with OAuth2 support using Google and GitHub login providers.
## Related Issue
Closes #42
## Changes
- Add OAuth2 authentication flow
- Create login/signup pages
- Add user session management
## Testing
- [x] Unit tests for auth service
- [x] Integration tests for OAuth flow
- [ ] Manual testing on staging
## Screenshots
[Before/After images]
## Checklist
- [x] Code follows style guide
- [x] Tests pass
- [x] Documentation updated
PR Templates
Create .github/PULL_REQUEST_TEMPLATE.md:
## Description
[Describe what this PR does]
## Related Issue
Closes #[issue number]
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## How Has This Been Tested?
[Describe test cases]
## Checklist
- [ ] Code follows project style
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] Tests added/updated
Code Review Best Practices
| Do | Don't |
|---|---|
| Review the intent, not just code style | Leave vague comments like "fix this" |
| Suggest, don't command | Request changes without explanation |
| Review in small batches (under 400 lines) | Approve PRs you haven't read |
| Use GitHub's suggestion feature | Review when tired or rushed |
| Acknowledge good code too | Focus only on negatives |
| Respond to comments promptly | Let PRs sit for days |
Automating Workflows
Link issues and PRs with keywords:
Closes #42
Fixes #42
Resolves #42
These auto-close the issue when the PR merges.
Use GitHub Actions to automate PR checks:
# .github/workflows/pr-checks.yml
name: PR Checks
on: pull_request
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run lint
run: npm run lint
Common Errors
| Error | Cause | Fix |
|---|---|---|
| Issue number not linked | Missing keyword | Edit PR description to include Closes #n |
| PR too large | Too many changes | Split into smaller PRs |
| Merge conflicts | Outdated branch | Rebase on latest target branch |
| CI checks failing | Code doesn't pass tests | Fix before requesting review |
| Review requested wrong person | Wrong team assignment | Use CODEOWNERS file |
| Draft PR accidentally ready | Wrong PR type | Convert to draft |
| Labels not showing | Missing label definitions | Create labels in repo settings |
| Template not applying | Wrong file location | Verify .github/ directory |
Practice Questions
Challenge
Create a GitHub repository with issue templates for bug reports and feature requests, plus a pull request template. Create three issues with labels and milestones. Open two branches, make changes, and create pull requests linking to the issues. Complete the full review cycle with changes requested, addressed, and approved.
Real-World Task
Set up a repository with branch protection requiring at least one review before merging. Create a CODEOWNERS file that auto-assigns reviewers for different directories. Add a CI/CD workflow that runs tests on every pull request. This setup is standard at DodaTech for projects like Durga Antivirus Pro, where code quality and review processes are mandatory.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro