Origin vs Upstream in Git: Key Differences and Usage
origin is the default name for the remote repository you clone from, while upstream usually refers to the original repository you forked from. origin points to your copy, and upstream points to the source repository to keep your fork updated.Quick Comparison
Here is a quick table comparing origin and upstream in Git to highlight their main differences.
| Factor | origin | upstream |
|---|---|---|
| Definition | Default remote for your cloned repo | Remote for the original source repo |
| Common Use | Push and pull your own changes | Fetch updates from the original repo |
| Set Automatically? | Yes, on clone | No, added manually if forked |
| Typical URL | Your fork or personal repo URL | Original project repo URL |
| Purpose | Manage your copy of the repo | Keep your fork synced with source |
| Command Example | git push origin main | git fetch upstream |
Key Differences
origin is the default name Git gives to the remote repository you clone from. When you clone a repo, Git automatically sets origin to point to that remote URL. You use origin to push your changes and pull updates from your own copy of the repository.
upstream is not set automatically. It is a conventional name used when you fork a repository. Your fork is your origin, and the original repository you forked from is called upstream. You add upstream manually to fetch changes from the original source to keep your fork updated.
In summary, origin points to your personal or team remote repo, while upstream points to the original project repo you want to track and sync with. This setup is common in open source workflows where you fork a project, work on your fork (origin), and regularly pull updates from the main project (upstream).
Code Comparison
Here is how you work with origin to push and pull changes from your own remote repository.
git clone https://github.com/yourusername/yourrepo.git cd yourrepo git push origin main git pull origin main
Upstream Equivalent
Here is how you add and use upstream to fetch updates from the original repository you forked from.
git remote add upstream https://github.com/originalowner/originalrepo.git
git fetch upstream
git merge upstream/mainWhen to Use Which
Choose origin when: You want to push your changes or pull updates from your own remote repository, such as your fork or team repo.
Choose upstream when: You forked a repository and want to fetch and merge changes from the original source to keep your fork up to date.
This distinction helps you manage your own work separately from the original project and collaborate smoothly.
Key Takeaways
origin is your default remote pointing to your cloned or forked repo.upstream is a manually added remote pointing to the original source repo.origin to push your changes and pull from your copy.upstream to fetch and merge updates from the original project.