GitHub
fork
diff
code comparison
version control

How to view diff of a forked github project

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

When you fork a GitHub repository, the useful comparison is usually "what changed in my fork relative to the upstream project?" You can answer that either in the GitHub web UI with the compare view or locally with a second remote that points at the upstream repository.

Use the GitHub Compare View

If the fork still shares common history with the original repository, the web compare page is often the fastest approach. The idea is to compare branches across repositories, not just inside the same repository.

A typical compare URL looks like this:

text
https://github.com/upstream-owner/repo/compare/main...your-user:main

That shows commits and file diffs that exist on your forked branch but not on the upstream branch. If the branch names differ, replace them accordingly.

This is useful when you want a quick visual answer without cloning anything locally.

Add an upstream Remote Locally

For repeated work, local Git is more flexible. Add the original repository as upstream:

bash
git remote add upstream https://github.com/upstream-owner/repo.git
git fetch upstream
git fetch origin

Now you can compare your fork branch against the upstream branch directly:

bash
git diff upstream/main origin/main

Or if you are already checked out on your branch:

bash
git diff upstream/main

This gives you the full patch in the terminal and can be narrowed to specific files if needed.

Compare Commits, Not Just Files

Sometimes you care more about which commits are unique than about the raw file patch. git log is better for that:

bash
git log --oneline upstream/main..origin/main

That shows commits present in your fork branch and absent from upstream. The reverse direction shows what upstream has that your fork does not:

bash
git log --oneline origin/main..upstream/main

This is especially useful before syncing your fork, preparing a pull request, or deciding whether your branch has diverged significantly.

Compare a Pull Request Branch

If the interesting work is on a feature branch rather than main, compare that branch explicitly:

bash
git diff upstream/main origin/feature/my-change

This is effectively what reviewers care about when a fork submits a pull request into the upstream repository. You can also open a pull request on GitHub and inspect the same diff in the PR UI.

Choose the Right Tool

Use the GitHub compare page when:

  • you want a fast visual overview
  • you are sharing the diff with others
  • the branch relationship is simple

Use local Git when:

  • you need terminal output
  • you want to script checks around the diff
  • you are comparing unusual branches or filtering by paths

Both approaches rely on the same underlying commit graph, so the best choice is the one that fits your workflow.

Common Pitfalls

  • Comparing against origin/main only and forgetting to fetch the real upstream repository. A fork normally has two relevant remotes.
  • Using the compare page with the base and head reversed. The direction changes how GitHub presents the diff.
  • Assuming the default branch names match. Many repositories use main, but some still use master or a custom branch.
  • Interpreting git diff and git log as identical tools. One shows content differences, the other shows commit history differences.
  • Forgetting to fetch before comparing. Stale remote refs produce stale diffs.

Summary

  • To diff a fork against the original repository, compare your branch with the upstream branch.
  • On GitHub, use the compare view across repositories.
  • Locally, add the original repository as upstream and run git diff or git log.
  • Use git diff for file changes and git log for commit-level differences.
  • Fetch both remotes before comparing so the result reflects current history.

Course illustration
Course illustration

All Rights Reserved.