How to Add Upstream in Git?
Adding an upstream repository in Git involves configuring your local repository to recognize and fetch changes from the original project repository. Here’s a step-by-step guide to adding an upstream repository:
Step 1: Clone the forked repository
You can clone you forked repository using `git clone` command:
git clone <link_of_your_fork>
for example purpose, lets clone an open source project Turing.jl:
git clone https://github.com/shravanngoswamii/Turing.jl.git
Step 2: Navigate to Cloned Repo
Now navigate to the clone of your forked repository using `cd` command:
cd <your_cloned_repo>
After navigating, check the name of remote repository using:
git remote -v
for example,
cd Turing.jl
git remote -v
Step 3: Add Upstream Remote
You can see that the name of the clone of your forked repository is `origin`. So now just add the original repository as an upstream using:
git remote add upstream <upstream_repository_URL>
for example,
git remote add upstream https://github.com/TuringLang/Turing.jl.git
Step 4: Verify Upstream Remote
You can verify that the upstream remote has been added correctly by listing the configured remotes using the git remote -v command:
git remote -v
How to Add Upstream in Git?
When you fork a repository, you create a copy of it under your own account. However, as the original repository updates with new features, bug fixes, and improvements, you’ll want to keep your forked repository up-to-date with these changes. This is where adding an upstream remote in Git comes into play. In this article, we’ll explore the process of adding an upstream remote to your forked repository, fetching changes from the original repository, and keeping your fork synchronized with the latest updates.
Table of Content
- What is upstream?
- How to Add Upstream in Git?
- Add Upstream after Cloning the Original Repo