DEV Community

Cover image for # Updating a forked Repo with Origin
Aditya
Aditya

Posted on

# Updating a forked Repo with Origin

You are looking to contribute to an awesome project on GitHub and you finally find it and fork the repo. a few weeks later you worked on the forked repo but are afraid the fork is way behind the original repo. how would you keep it up to date? here is how

Below are the steps to always keep the forked repo up to date with its original repo

1.Add the remote/original repo and lets call it upstream

$ git remote add upstream https://github.com/original-repo/repo-name.git
Enter fullscreen mode Exit fullscreen mode

2.Fetch all branches from remote upstream

$ git fetch upstream
Enter fullscreen mode Exit fullscreen mode

3.Use git rebase to re-write your master with upstreamโ€™s master. Note: rebase will fail, if you have uncommitted changes in your forked master

$ git rebase upstream/master
Enter fullscreen mode Exit fullscreen mode

4.Push your updates to master using force

$ git push origin master --force
Enter fullscreen mode Exit fullscreen mode

Top comments (0)