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)

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: