Introduction
Pull requests (PRs) are GitHub’s primary mechanism for proposing, reviewing, and integrating code changes. This guide covers the essential workflow for creating and reviewing pull requests - core skills for collaborative bioinformatics development.
What we’ll cover:
- Creating a branch and making changes
- Opening a pull request
- Reviewing code and suggesting changes
- Addressing feedback and merging
The Pull Request Workflow
Step 1: Create a Branch
Branches allow you to develop features or fixes in isolation from the main codebase.
Using Git commands:
# Create and switch to a new branch
git checkout -b feature/add-quality-filter
# Make your changes to files
# ... edit your code ...
# Stage and commit your changes
git add .
git commit -m "Add quality filtering to alignment script"
# Push the branch to GitHub
git push -u origin feature/add-quality-filterUsing GitHub web interface:
- Navigate to your repository
- Click the branch dropdown (usually says “main”)
- Type a new branch name and select “Create branch”
Use descriptive names with prefixes:
feature/for new featuresfix/orbugfix/for bug fixesdocs/for documentation updatesrefactor/for code refactoring
Step 2: Make Your Changes
Edit your files, add new code, update documentation, etc. Commit your changes with clear, descriptive messages.
Good commit messages:
git commit -m "Add PHRED quality score filter to alignment preprocessing"Less helpful commit messages:
git commit -m "update code" # Too vague
git commit -m "fix" # What was fixed?Step 3: Open a Pull Request
From the GitHub web interface:
- Navigate to the repository on GitHub
- You’ll often see a yellow banner suggesting “Compare & pull request” for recently pushed branches
- Alternatively, click “Pull requests” tab → “New pull request”
- Select your branch to merge from and the target branch (usually
main) to merge into - Fill in the PR template:
Example PR Description:
## Description
Adds quality filtering step to remove low-quality reads before alignment.
## Changes
- Added `filter_by_quality()` function to preprocessing module
- Updated alignment pipeline to call filtering step
- Added unit tests for quality filtering
## Testing
- [x] Unit tests pass
- [x] Tested with sample datasets (SRR12345, SRR67890)
## Related Issues
Closes #42- Small and focused: Addresses one feature/fix, not multiple unrelated changes
- Well-described: Clear title and description of what and why
- Tested: Includes or references tests for the changes
- Links to issues: References related issue numbers (e.g., “Fixes #123”)
Branch vs Fork: When to Use Which?
Use a branch when:
- You’re a collaborator on the repository
- Working within your organization’s repos
- You have write access
Use a fork when:
- Contributing to external/open-source projects
- You don’t have write access to the repository
- You want to experiment without affecting the original repo
Fork workflow:
- Click “Fork” button on the repository
- Clone your fork:
git clone https://github.com/YOUR-USERNAME/repo-name.git - Create a branch in your fork
- Make changes and push to your fork
- Create a PR from your fork to the original repository
Code Review
Step 4: Review a Pull Request
As a reviewer:
Navigate to the PR:
- Go to “Pull requests” tab
- Click on the PR to review
Review the “Files changed” tab:
- Examine all modified files
- Look for:
- Logic errors or bugs
- Code style consistency
- Missing edge cases or error handling
- Unclear variable/function names
- Missing tests or documentation
- Security issues
Leave comments:
Inline comments (single line):
- Hover over a line number
- Click the blue
+icon - Write your comment
- Click “Add single comment” for immediate posting
Suggestion comments (suggesting specific code changes):
- Click the
+icon on a line - Click the “Insert a suggestion” button (±)
- Edit the code in the suggestion block
- Add explanation above the suggestion
- The author can accept your suggestion with one click!
Example:
Consider using a more descriptive variable name here: ```suggestion quality_threshold = 30 # Minimum PHRED score ```Start a review (for multiple comments):
- Click “Start a review” instead of “Add single comment”
- Add all your comments
- Click “Finish your review” button (top right)
- Choose:
- Comment: General feedback without approval status
- Approve: Changes look good, ready to merge
- Request changes: Issues must be addressed before merging
- Be constructive and kind: “Consider using X because Y” rather than “This is wrong”
- Explain the why: Don’t just say what to change, explain why it’s important
- Distinguish between blockers and suggestions: Be clear about what must change vs. nice-to-haves
- Praise good work: Call out clever solutions or improvements
- Ask questions: “Could you help me understand why we need this?” is often better than assuming
Step 5: Address Review Feedback
As the PR author:
Respond to comments:
- Answer questions
- Discuss suggestions
- Explain your reasoning if you disagree
Make requested changes:
# Make the changes in your local branch # ... edit files ... # Commit the changes git add . git commit -m "Address review feedback: improve variable naming" # Push to the same branch git pushThe PR will automatically update with your new commits!
Accept suggested changes:
- If a reviewer used the suggestion feature, you can click “Commit suggestion” to apply it directly (pull changes locally before pushing new changes!)
Request re-review:
- Click the refresh icon next to a reviewer’s name to notify them you’ve addressed their feedback.
Step 6: Merge the Pull Request
Once approved and all checks pass:
Choose merge strategy:
- Create a merge commit: Preserves all commits and adds a merge commit (default)
- Squash and merge: Combines all commits into one (cleaner history)
- Rebase and merge: Replays commits on top of base branch (linear history)
Click the merge button
Delete the branch (optional but recommended to keep repo tidy)
Repository admins can require:
- Minimum number of approving reviews
- Passing CI/CD checks before merging
- Up-to-date branches before merging
- Specific reviewers (code owners)
Common Scenarios
Scenario 1: PR has merge conflicts
# Update your local main branch
git checkout main
git pull origin main
# Switch to your feature branch
git checkout feature/your-branch
# Merge main into your branch
git merge main
# Resolve conflicts in your editor
# ... fix conflicts ...
# Commit the resolution
git add .
git commit -m "Resolve merge conflicts with main"
git pushScenario 2: Updating your fork
# Add the original repo as upstream (one-time setup)
git remote add upstream https://github.com/ORIGINAL-OWNER/repo-name.git
# Fetch upstream changes
git fetch upstream
# Merge upstream changes into your branch
git merge upstream/main
git pushQuick Reference
| Task | Command |
|---|---|
| Create branch | git checkout -b branch-name |
| Push branch | git push -u origin branch-name |
| Update branch from main | git merge main |
| View PR locally | gh pr checkout PR-NUMBER (requires GitHub CLI) |
| List open PRs | gh pr list |
Additional Resources
- GitHub’s Pull Request Documentation
- How to Write a Git Commit Message
- GitHub CLI - Command-line tool for working with PRs
- Code Review Best Practices