# How to Compare Branches Across Forked Repositories on GitHub

> Easily compare branches across GitHub forks using a special URL syntax. View diffs instantly between your repository and any fork to streamline your review process.

- Repository: [Tim Green/github-cheat-sheet](https://github.com/tiimgreen/github-cheat-sheet)
- Tags: how-to-guide
- Published: 2026-03-06

---

**GitHub enables cross-repository branch comparisons by supporting a specialized URL syntax that prefixes the fork branch with the fork owner's username and a colon, allowing you to view diffs directly in the browser.**

Comparing branches across forked repositories is a critical workflow for reviewing contributions before submitting pull requests. The `tiimgreen/github-cheat-sheet` repository documents this technique in its comprehensive guide to GitHub features. By constructing a specific compare URL, you can analyze differences between any branch in a fork and any branch in the upstream or another repository without cloning locally.

## The Fork Comparison URL Pattern

GitHub's compare endpoint accepts a range expression that spans across repository boundaries. The canonical URL structure follows this pattern:

```text
https://github.com/{owner}/{repo}/compare/{fork-owner}:{fork-branch}...{base-branch}

```

- **`{owner}/{repo}`** – The base repository you are viewing (typically the upstream).
- **`{fork-owner}`** – The username or organization that owns the fork.
- **`{fork-branch}`** – The specific branch name in the forked repository.
- **`{base-branch}`** – The target branch in the base repository (commonly `main` or `master`).

When you navigate to this URL, GitHub renders the standard diff view showing files changed, commit history, and line-by-line differences.

## How Cross-Repository Comparison Works

Under the hood, GitHub interprets the range `<ref>...<ref>` by resolving each reference in its respective repository context. By prefixing the left-hand reference with `{fork-owner}:`, you instruct GitHub to resolve that ref within the forked repository namespace while the right-hand ref resolves in the current repository.

GitHub then calculates a temporary merge-base between these two branches and generates the diff view. This mechanism is implemented in the compare endpoint handling, as documented in the cheat sheet.

## Practical Examples

### Compare Fork Master Against Upstream Master

To see what changes exist between the `master` branch of a fork owned by `byroot` and the official `rails/rails` repository:

```text
https://github.com/rails/rails/compare/byroot:master...master

```

This displays exactly how the fork's `master` diverges from the upstream `master` branch.

### Compare a Feature Branch to Upstream Development

When reviewing a feature branch from a contributor before merging:

```text
https://github.com/your-org/your-repo/compare/fork-user:feature-awesome...develop

```

Replace `your-org/your-repo` with the upstream repository path, `fork-user` with the contributor's username, and `feature-awesome` with their branch name.

### Quick Access via Markdown Links

You can embed these comparisons directly in documentation or pull request comments:

```markdown
[Compare my fork's bugfix](https://github.com/owner/repo/compare/my-fork:bugfix...master)

```

Clicking the link opens the comparison view instantly, streamlining code review workflows.

## Source Reference in github-cheat-sheet

This technique is officially documented in the `tiimgreen/github-cheat-sheet` repository. The specific implementation details and URL pattern appear in **README.md** at lines 76 through 84, under the section titled "Compare Branches across Forked Repositories"【/cache/repos/github.com/tiimgreen/github-cheat-sheet/master/README.md#L76-L84】.

The cheat sheet serves as the canonical reference for this advanced GitHub feature, providing the foundational syntax used by developers to perform cross-fork comparisons.

## Summary

- **Use the triple-dot syntax** with an owner prefix (`fork-owner:branch...base-branch`) to compare across repository boundaries.
- **Reference the upstream repository** in the base URL path while specifying the fork details in the compare parameter.
- **Access the full diff view** including files changed and commit history directly in the browser without local clones.
- **Find the original documentation** in [`tiimgreen/github-cheat-sheet/README.md`](https://github.com/tiimgreen/github-cheat-sheet/blob/main/tiimgreen/github-cheat-sheet/README.md) lines 76-84 for the authoritative source.

## Frequently Asked Questions

### How do I construct the URL to compare a forked branch against an upstream branch?

Construct the URL using the pattern `https://github.com/{upstream-owner}/{repo}/compare/{fork-owner}:{branch}...{upstream-branch}`. The key element is prefixing the fork branch with the fork owner's username followed by a colon, which tells GitHub to resolve that reference in the fork's namespace.

### Can I compare branches between two different forks using this method?

Yes. While commonly used to compare a fork against its upstream, the syntax supports comparing any two repositories where you have access. Simply set the base repository in the URL path and use the `owner:branch` prefix for the comparison target in the fork parameter.

### What does the colon (`:`) do in the comparison URL?

The colon acts as a namespace separator. When GitHub parses the compare range `{fork-owner}:{branch}...{target}`, it resolves the left side within the `{fork-owner}`'s repository fork while resolving the right side within the repository specified in the base URL path.

### Where is this feature documented in the GitHub ecosystem?

The authoritative documentation for this cross-fork comparison technique resides in the `tiimgreen/github-cheat-sheet` repository, specifically in the [`README.md`](https://github.com/tiimgreen/github-cheat-sheet/blob/main/README.md) file at lines 76-84, which details the URL construction and usage patterns.