Member-only story
Update Forked GitHub Repository with the Original GitHub Repository

This is a common issue: We fork a Github Repository and, after a while, when the same repository is untouched for a month, we don’t know how to pull the latest updates from the original repository.
In this article, you’ll learn how to get the latest updates from an original repository into a forked repository.
This article assumes some git
basics, but we’ll also dive into those below, before moving forward with the required steps to get updates from an original repository into a forked repository.
Add Remote Repository in Git
Every repository in your local git needs to be linked to one or many Github repositories. But would you like to always type or copy/paste the URL for that particular Github repository whenever you need to push to/pull from/fetch from the remote repository? We as developers need to always work for an easier and lazier solution, don’t we? Thus, we link the URL to a variable in git i.e., origin
, myrepo
etc.
Thus, for example, to add the remote repository’s URL to a variable myrepo
, here is how you do it.
git remote add myrepo https://github.com/krishbhanushali/my-repo.git
If you want to update the above myrepo
variable to a different remote repository’s URL then you can do the following:
git remote set-url myrepo https://github.com/krishbhanushali/my-repo-1.git
Pull vs Fetch
Pull: To get the updates from the remote repository and integrate those changes in your working files, we use PULL. Here is an example where you can pull the updates from the remote repository into a branch.
git pull myrepo master
The above command will get you the latest updates from the remote repository’s master
branch into your local repository’s master
branch.
Fetch: Fetch gets you the updates from the remote repository but does not affect any of your working files. It is quite harmless, meaning it will not update, delete, or create any new files in your working local git repository. To fetch from the remote repository, you just need to specify the remote repository.