Forking and Pull Requests on GitHub

Forking creates a personal copy of someone else's GitHub repository into a GitHub account. The fork is completely independent — changes made to the fork do not affect the original repository. However, the connection to the original project is maintained, making it easy to contribute back.

Forking is the foundation of open-source contribution. Instead of asking the project owner for direct write access, anyone can fork the project, make changes in their own copy, and then submit those changes back as a Pull Request.

Real-life analogy: Think of a fork as photocopying a recipe book. The photocopy can be marked up, pages can be changed, and notes can be added without touching the original. If the recipe is improved, a suggestion can be sent back to the original author.

How to Fork a Repository

  1. Go to the GitHub repository to fork
  2. Click the "Fork" button in the top-right corner of the repository page
  3. Select the account to fork into
  4. GitHub creates a copy of the repository in the account

The forked repository will now appear at: https://github.com/your-username/original-repo-name

Fork → Clone → Modify → Push Workflow

# Step 1: Fork the repo on GitHub (done via browser)

# Step 2: Clone the forked repo to local machine
git clone https://github.com/myusername/project.git
cd project

# Step 3: Add the original repo as "upstream" remote
git remote add upstream https://github.com/originalauthor/project.git

# Step 4: Create a new branch for the changes
git checkout -b fix-typo-in-readme

# Step 5: Make the changes
# ... edit files ...

# Step 6: Commit and push to the fork
git add .
git commit -m "Fix typo in README"
git push origin fix-typo-in-readme

# Step 7: Go to GitHub and open a Pull Request

Keeping a Fork Updated

When the original repository gets new commits, the fork will be behind. The fork can be updated by pulling from the upstream:

# Fetch changes from the original project
git fetch upstream

# Switch to the main branch
git checkout main

# Merge upstream changes into local main
git merge upstream/main

# Push the updated main to the fork
git push origin main

What is a Pull Request?

A Pull Request (PR) is a formal way to propose changes to a repository on GitHub. Instead of directly merging code, a PR creates a discussion space where the project maintainer and other contributors can:

  • Review the code changes line by line
  • Leave comments and suggestions
  • Request modifications
  • Approve and merge the changes when satisfied

Pull Requests are used in two main scenarios:

  1. Between branches — When working in a team and changes from a feature branch need to be merged into main
  2. Between forks — When contributing to someone else's open-source project

Creating a Pull Request on GitHub

  1. Push the branch with changes to GitHub
  2. Go to the repository on GitHub
  3. GitHub usually shows a yellow banner saying "Your branch had recent pushes" — click "Compare & pull request"
  4. Or go to the "Pull requests" tab and click "New pull request"
  5. Select the base branch (where the changes will go, e.g., main) and the compare branch (the branch with changes)
  6. Write a title and description for the PR:
    • Explain what was changed and why
    • Reference any related issues (e.g., "Fixes #42")
    • Add screenshots if relevant (for UI changes)
  7. Click "Create pull request"

Writing a Good Pull Request Description

A well-written PR description speeds up the review process:

## What does this PR do?
Fixes the login button that was unresponsive on mobile devices.

## How was it tested?
Tested on iPhone 12 (Safari) and Android Chrome.

## Related Issue
Fixes #27

## Screenshots
[Before screenshot] [After screenshot]

Reviewing a Pull Request

As a reviewer, GitHub shows a "Files changed" tab with all the line-by-line differences. Reviewers can:

  • Click on a specific line to add a comment
  • Approve the PR (it is ready to merge)
  • Request changes (modifications are needed before merging)
  • Simply comment without a formal decision

Merging a Pull Request

Once the PR is approved, it can be merged using one of three methods:

MethodDescriptionWhen to Use
Merge CommitCreates a merge commit — preserves all commits from the branchGeneral use — keeps full history
Squash and MergeCombines all branch commits into a single commitWhen the branch has many small/messy commits
Rebase and MergeReplays commits on top of the base branchFor a clean, linear history

Closing a Pull Request Without Merging

If a PR is no longer needed or was submitted by mistake, it can be closed without merging by clicking "Close pull request" at the bottom of the PR page.

Draft Pull Requests

A Draft PR signals that the work is still in progress and should not be merged yet. It allows early feedback and discussion. To create a draft PR, click the dropdown arrow next to "Create pull request" and select "Create draft pull request".

Summary

Forking creates a personal copy of someone else's repository to work on freely. A Pull Request is a proposal to merge changes into a project. PRs provide a space for code review, discussion, and quality control before changes go into the main codebase. Together, forking and PRs form the backbone of open-source collaboration on GitHub.

Leave a Comment

Your email address will not be published. Required fields are marked *