How to update a forked repo from original one

Sync new changes from original reposiotry to your repository

Velu S Gautam1 min readLearnings

You can update your forked repository with changes from the original repo using the steps below.

clone

git remote add upstream

git fetch upstream

git merge / rebase upstream/master

git push origin master

origin
(your fork)

local repo

upstream
(original repo)

Step 1: Go to your local repository folder

BASH
cd project_folder

Step 2: Change to master, or whichever branch you want to pull changes into

BASH
git checkout master

Step 3: Verify your current origins are configured for fetch and push with the command below

BASH
git remote -v

Step 4: Add an upstream remote to your local repository with the command below

BASH
git remote add upstream https://github.com/-username-/-original-repository.git

Step 5: Verify the upstream remote was added

BASH
git remote -v

It should now show 4 lines, 2 for origin and 2 for upstream, where origin is your repository and upstream is the original repository you forked from.

Step 6: Fetch all changes from the original repository

BASH
git fetch upstream

Step 7: Merge the changes into your branch, or rebase instead if you prefer.

BASH
git merge upstream/master

Or

BASH
git rebase upstream/master

Step 8: Push the new changes to your repository.

If you rebased, your history has diverged from origin, so you'll need a force push. Check the warnings first, and if everything looks right, force-push:

BASH
git push origin master --force

Comments