Working with Multiple Remotes
What you'll learn: How to manage workflows when your local Git repository connects to multiple remote repositories, especially when working with forked projects.
Why Multiple Remotes?
So far, you've worked with a single remote called origin—typically your own repository on GitHub or GitLab. But what happens when you fork someone else's project?
The fork workflow creates two remotes:
origin: Your personal fork (where you push your work)upstream: The original repository you forked from (where you pull updates)
Think of it like subscribing to a newsletter (upstream) while keeping your own annotated copy (origin). You read updates from the original source but write your notes in your personal copy.
How It Works
When you fork a repository and clone it, Git automatically sets your fork as origin. You then manually add the original repository as upstream:
git remote add upstream <original-repo-url>
Now you can:
- Pull updates from
upstreamto stay current with the original project - Push your changes to
origin(your fork) - Create pull requests from your fork back to the upstream repository
This separation keeps your experimental work isolated while letting you sync with the project's main development.
Common Workflow
git fetch upstream # Get latest changes from original
git merge upstream/main # Integrate them into your branch
git push origin main # Update your fork
Key Takeaway: Multiple remotes let you maintain your own workspace (origin) while staying synchronized with a parent project (upstream), essential for contributing to open-source projects or collaborating across forked repositories.