This comprehensive guide walks you through every step of the pull request process, from finding a project to getting your changes merged.
Before making any changes, thoroughly read:
Result: You now have a copy at https://github.com/YourUsername/ProjectName
# Clone your fork (not the original repository)
git clone git@github.com:YourUsername/ProjectName.git
# Navigate to the project directory
cd ProjectName
# Verify the remote URL
git remote -v
# Should show: origin git@github.com:YourUsername/ProjectName.git
This allows you to sync with the original repository:
# Add the original repository as upstream
git remote add upstream git@github.com:OriginalOwner/ProjectName.git
# Verify remotes
git remote -v
# Should show both origin (your fork) and upstream (original)
# Install project dependencies
npm install # Node.js
pip install -r requirements.txt # Python
bundle install # Ruby
# Run tests to ensure everything works
npm test
python -m pytest
bundle exec rspec
Never work directly on the main branch!
# Ensure you're on the main branch
git checkout main
# Pull latest changes from upstream
git pull upstream main
# Create and switch to a new branch
git checkout -b descriptive-branch-name
# Examples of good branch names:
git checkout -b fix-login-validation
git checkout -b add-user-avatar-upload
git checkout -b update-installation-docs
Let's say you're fixing a validation bug:
// Before (buggy code)
function validateEmail(email) {
return email.includes('@'); // Too simple!
}
// After (proper validation)
function validateEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
# Run the full test suite
npm test
# Run specific tests
npm test -- --grep "email validation"
# Manual testing
npm start # Start the application and test manually
# Check what files have changed
git status
# Review your changes
git diff
# Stage specific files
git add src/utils/validation.js
git add tests/validation.test.js
# Or stage all changes
git add .
# Commit with a descriptive message
git commit -m "Fix email validation to use proper regex
- Replace simple @ check with comprehensive regex pattern
- Add test cases for edge cases
- Fixes #123"
Good commit messages:
Fix email validation regex pattern
Add user avatar upload functionality
Update installation instructions for Windows
docs: Fix typo in API documentation
Bad commit messages:
fix
update stuff
changes
working on feature
# Push your branch to your fork
git push origin fix-login-validation
# If this is the first push for this branch, Git will show a helpful message
Most projects have a PR template. Fill it out completely:
## Description
Brief summary of changes made.
## Type of Change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update
## Testing
- [x] I have tested these changes locally
- [x] I have added tests that prove my fix is effective
- [x] All new and existing tests pass
## Related Issues
Fixes #123
Related to #456
## Screenshots (if applicable)
[Include screenshots for UI changes]
## Checklist
- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
Code Style Issues:
// Reviewer comment: "Please use const instead of let for variables that don't change"
// Before
let apiUrl = 'https://api.example.com';
// After
const apiUrl = 'https://api.example.com';
Performance Concerns:
// Reviewer comment: "This loop is inefficient for large arrays"
// Before
function findUser(users, id) {
for (let user of users) {
if (user.id === id) return user;
}
}
// After
function findUser(users, id) {
return users.find(user => user.id === id);
}
# Make the requested changes
# Stage and commit
git add .
git commit -m "Address review feedback
- Use const instead of let for unchanging variables
- Replace manual loop with Array.find() method
- Add JSDoc comments for better documentation"
# Push the updates
git push origin fix-login-validation
If the main branch has changed since you started:
# Fetch latest changes
git fetch upstream
# Switch to main and update
git checkout main
git pull upstream main
# Switch back to your branch
git checkout fix-login-validation
# Rebase onto latest main
git rebase main
# If conflicts occur, resolve them in your editor
# Then continue the rebase
git add .
git rebase --continue
# Force push the rebased branch
git push --force-with-lease origin fix-login-validation
Once your PR is merged:
# Switch to main branch
git checkout main
# Pull the latest changes (including your merged PR)
git pull upstream main
# Delete your feature branch locally
git branch -d fix-login-validation
# Delete the remote branch
git push origin --delete fix-login-validation
# Push updated main to your fork
git push origin main
After your first successful PR:
Remember: every expert was once a beginner. Your first PR might not be perfect, but each one teaches you something new about collaborative software development.
The pull request workflow is the foundation of modern software collaboration. Master it, and you'll be equipped to contribute to any open source project in the world!