1. Home
  2. /
  3. How to Submit a Pull Request: A Complete Guide
  4. /
  5. Step-by-Step Pull Request Workflow: From Fork to Merge
Step-by-Step Pull Request Workflow: From Fork to Merge
Headbanger
September 19, 2025
|
8 min read

Step-by-Step Pull Request Workflow: From Fork to Merge

This comprehensive guide walks you through every step of the pull request process, from finding a project to getting your changes merged.

Phase 1: Project Discovery and Preparation

Step 1: Find a Suitable Project

Good First Projects

  • Documentation fixes - typos, unclear instructions
  • Good first issue labels on GitHub
  • Small bug fixes - broken links, minor functionality issues
  • Test improvements - adding missing test cases

Project Evaluation Checklist

  • ✅ Active maintenance (recent commits)
  • ✅ Clear contribution guidelines
  • ✅ Welcoming community (check issue discussions)
  • ✅ Good documentation
  • ✅ Reasonable test coverage

Step 2: Read the Documentation

Before making any changes, thoroughly read:

  1. README.md - Understanding the project
  2. CONTRIBUTING.md - Contribution guidelines
  3. Issues - Existing problems and discussions
  4. Pull Requests - Examples of accepted contributions

Phase 2: Setting Up Your Workspace

Step 3: Fork the Repository

  1. Navigate to the project repository on GitHub
  2. Click the "Fork" button in the top-right corner
  3. Select your account as the destination
  4. Wait for the forking process to complete

Result: You now have a copy at https://github.com/YourUsername/ProjectName

Step 4: Clone Your Fork

# 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

Step 5: Set Up Upstream Remote

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)

Step 6: Install Dependencies and Test

# 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

Phase 3: Making Changes

Step 7: Create a Feature Branch

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

Step 8: Make Your Changes

Development Best Practices

  1. Focus on one issue per pull request
  2. Follow project coding standards
  3. Write meaningful commit messages
  4. Add tests for new functionality
  5. Update documentation as needed

Example: Fixing a Bug

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);
}

Step 9: Test Your Changes

# 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

Step 10: Stage and Commit Changes

# 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"

Commit Message Best Practices

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

Phase 4: Submitting the Pull Request

Step 11: Push Your Branch

# 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

Step 12: Create the Pull Request

  1. Navigate to your fork on GitHub
  2. Click "Compare & pull request" (appears after pushing)
  3. Or manually create:
    • Go to original repository
    • Click "New pull request"
    • Click "compare across forks"
    • Select your fork and branch

Step 13: Fill Out the PR Template

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

Phase 5: Review and Iteration

Step 14: Respond to Feedback

Common Review Comments

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);
}

Making Changes After Review

# 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

Step 15: Handle Merge Conflicts

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

Phase 6: Success and Cleanup

Step 16: Celebrate Your Merged PR! 🎉

Once your PR is merged:

  1. Thank the reviewers for their time and feedback
  2. Close related issues if applicable
  3. Share your success on social media or dev communities

Step 17: Clean Up

# 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

Tips for Success

During Development

  • Keep changes small and focused
  • Test thoroughly before submitting
  • Follow project conventions religiously
  • Write clear commit messages

During Review

  • Be patient - reviews take time
  • Be receptive to feedback
  • Ask questions if feedback is unclear
  • Make changes promptly

Communication

  • Be polite and professional
  • Explain your reasoning for choices made
  • Thank reviewers for their time
  • Help other contributors when you can

Common Pitfalls to Avoid

  1. Working on main branch instead of feature branch
  2. Making too many changes in one PR
  3. Not testing changes thoroughly
  4. Ignoring project guidelines
  5. Taking feedback personally
  6. Abandoning PRs after initial submission

What's Next?

After your first successful PR:

  1. Look for more issues to work on
  2. Help review other contributors' PRs
  3. Become a regular contributor
  4. Share your knowledge with newcomers

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!