Pull Requests from Forks

Learn how to contribute to projects by creating pull requests from forked repositories on GitHub.

Creating Pull Requests from Forks

Contributing to open-source projects often involves forking a repository and submitting changes through pull requests. This workflow is foundational to collaborative development on GitHub and enables contributions without direct write access to the original repository.

The Fork and PR Workflow

  • Fork: Create a personal copy of someone else's project
  • Clone: Download your fork to your local machine
  • Branch: Create a new branch for your changes
  • Commit: Make and commit your changes
  • Push: Upload your changes to your fork
  • Pull Request: Propose your changes to the original project
  • Allows contributions without direct repository access
  • Provides isolated environment to experiment
  • Enables project maintainers to review changes before merging
  • Creates a permanent record of contribution discussions
  • Helps maintain quality control for projects

Creating a Pull Request from a Fork

    1. Fork the repository by clicking the "Fork" button in the top-right of the repository page
    2. Clone your fork to your local machine:
      git clone https://github.com/YOUR-USERNAME/REPOSITORY-NAME.git
      
    3. Set up the original repository as an "upstream" remote:
      git remote add upstream https://github.com/ORIGINAL-OWNER/REPOSITORY-NAME.git
      
    4. Create a new branch for your feature or bugfix:
      git checkout -b feature-branch-name
      
    5. Make your changes and commit them with descriptive messages
    6. Push your branch to your fork:
      git push origin feature-branch-name
      
    7. Navigate to the original repository on GitHub
    8. Click the "New pull request" button
    9. Click "compare across forks" and select your fork and branch
    10. Fill in the PR description and submit
💡Tip

Keeping your fork synchronized with the upstream repository is important. Regularly fetch and merge changes to avoid conflicts:

git fetch upstream
git checkout main
git merge upstream/main

Common Challenges and Solutions

To avoid out-of-date forks and potential merge conflicts:

# Update your local copy of the upstream repository
git fetch upstream

# Checkout your main branch
git checkout main

# Merge upstream changes
git merge upstream/main

# Push changes to your fork
git push origin main

When reviewers request changes:

  1. Make the requested changes in your local branch
  2. Commit the changes
  3. Push to your fork
  4. The PR will automatically update

Use git commit --amend and git push --force-with-lease to clean up commits before final review, but only if you understand the implications.

PR Etiquette for Forked Repositories

  • Read Contribution Guidelines: Most projects have a CONTRIBUTING.md file with specific requirements
  • One Feature Per PR: Keep pull requests focused on a single change
  • Be Responsive: Respond promptly to feedback and questions
  • Test Thoroughly: Ensure your changes work as expected
  • Write Clear Descriptions: Explain what your changes do and why they're needed
  • Be Patient: Maintainers may be busy; wait for feedback
⚠️Caution

Never force-push to a branch that already has an open PR unless specifically requested by the maintainers, as it makes reviewing changes difficult.

Additional Resources