git
github
version control
repositories
software development

What is the difference between origin and upstream on GitHub?

Master System Design with Codemia

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

Introduction

In GitHub workflows, origin and upstream are just remote names, but they represent very different collaboration roles. Confusing them can lead to wrong-target pushes or stale pull requests. A clear remote strategy keeps contribution flow predictable, especially in fork-based projects.

Remote Names Are Aliases, Not Special Keywords

Git remotes are local aliases for repository URLs. The names are not reserved, but conventions matter.

Most teams use:

  • 'origin for your writable fork or primary repo clone target.'
  • 'upstream for the canonical project repository.'

After cloning your fork, origin exists automatically.

bash
git clone https://github.com/your-user/project.git
cd project
git remote -v

Then add canonical source repository as upstream.

bash
git remote add upstream https://github.com/org/project.git
git remote -v

From then on, you fetch changes from upstream and push your branches to origin.

Why Fork Workflows Need Both

In open source and large internal platforms, contributors usually cannot push directly to canonical main branch. The two-remote model solves this:

  • Develop and push safely to your fork.
  • Pull latest canonical updates from upstream.
  • Open pull requests from fork branch to upstream mainline.

This separation lowers risk and keeps maintainer branches protected.

Daily Sync Flow That Prevents Drift

A clean and repeatable sync routine is critical.

bash
1git fetch --all --prune
2git switch main
3git merge --ff-only upstream/main
4git push origin main

Then rebase feature work on updated main:

bash
git switch feature/new-filter
git rebase main
git push --force-with-lease origin feature/new-filter

This produces cleaner pull requests and minimizes merge noise.

Inspect Tracking and Push Targets

Before pushing, inspect branch tracking so you do not accidentally update the wrong remote.

bash
git branch -vv
git remote show origin
git remote show upstream

If a branch tracks wrong remote, fix it explicitly:

bash
git branch --set-upstream-to=origin/feature/new-filter feature/new-filter

Use explicit pushes when multiple remotes are configured:

bash
git push origin feature/new-filter

This is safer than plain git push in multi-remote repositories.

Handling Repository URL Changes

Organizations rename repos, move projects, or change protocol from HTTPS to SSH. Keep remotes updated.

bash
git remote set-url origin [email protected]:your-user/project.git
git remote set-url upstream [email protected]:org/project.git

Then verify:

bash
git remote -v

Stale URLs are a common source of authentication and fetch confusion.

Multiple Remotes Beyond Two

Some teams add release mirrors or deployment remotes.

bash
git remote add release [email protected]:org/project-release.git
git fetch release

When you have many remotes, naming clarity is more important than tradition. Use names that express purpose and write access level.

Collaboration Policy That Scales

A simple policy avoids most mistakes:

  1. origin is always contributor writable remote.
  2. upstream is always canonical remote.
  3. Feature branches are pushed only to origin.
  4. Pull requests target upstream main branch.
  5. Local main is synced from upstream before rebasing feature branches.

Put this in contribution docs so onboarding is consistent.

Common Pitfalls

  • Assuming origin always points to canonical project.
  • Forgetting to fetch upstream before opening pull requests.
  • Using plain git push and hitting unintended remote.
  • Force-pushing without lease protection on shared branches.
  • Ignoring remote URL drift after repository migrations.

Summary

  • 'origin and upstream are remote aliases with different collaboration roles.'
  • In fork workflows, push to origin and sync from upstream.
  • Use explicit fetch and push commands to avoid wrong-target updates.
  • Keep tracking branches and remote URLs audited.
  • Standardized remote conventions reduce team-level Git errors.

Course illustration
Course illustration

All Rights Reserved.