Pull Requests and Code Review
Duration: 8 min
What is a Pull Request?
A Pull Request (PR) is a way to propose changes to a repository. It allows others to review your code before merging it into the main branch.
Creating a Pull Request on GitHub
First, push your branch to GitHub:
# Create a local branch
git checkout -b feature/add-validation
# Make changes
echo 'def validate_input(x):' >> model.py
echo ' return x is not None' >> model.py
# Commit changes
git add model.py
git commit -m 'Add input validation'
# Push to GitHub
git push origin feature/add-validationEnumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 250 bytes, done.
To github.com:username/my-ai-project.git
* [new branch] feature/add-validation -> feature/add-validationOpening a Pull Request
On GitHub, you'll see a prompt to create a PR:
- Click "Compare & pull request"
- Add a title: "Add input validation"
- Add a description explaining your changes
- Click "Create pull request"
Code Review Process
Once your PR is created, team members can:
- Review your code
- Comment on specific lines
- Request changes if needed
- Approve when satisfied
Example review comment:
This function looks good, but consider adding error handling for None values.Responding to Review Comments
# Make the requested changes
echo 'def validate_input(x):' > model.py
echo ' if x is None:' >> model.py
echo ' raise ValueError("Input cannot be None")' >> model.py
echo ' return True' >> model.py
# Commit and push
git add model.py
git commit -m 'Add error handling for None values'
git push origin feature/add-validationThe PR automatically updates with your new commits!
Merging a Pull Request
Once approved, merge the PR:
- Click "Merge pull request" on GitHub
- Choose merge strategy (usually "Create a merge commit")
- Click "Confirm merge"
- Delete the branch (optional but recommended)
Best Practices for PRs
| Practice | Why |
|---|---|
| Small PRs | Easier to review, faster feedback |
| Clear title | Reviewers understand the change |
| Detailed description | Context helps reviewers |
| Link issues | Tracks what problem it solves |
| Request reviewers | Gets feedback faster |
💡 Tip: Keep PRs focused on one feature. If you're adding validation AND preprocessing, make two separate PRs.
❓ What is the main purpose of a Pull Request?