It is very common to fork a repo you are interested in and start reading code and learn how things are done. Then after a few days realizing that the forked repo is already behind upstream and need to resync. Here is a standard way of doing just this safely.

We will call the main project to fork https://github.com/author/cool-project.git and the forked repo will be at https://github.com/myself/cool-project.git

From the forked repo we need to add the remote upstream (the original repo we have forked from)

git remote add upstream https://github.com/author/cool-project.git

Then we need to fetch all branches with

git fetch upstream

Let’s move to master branch on the forked repo

git checkout master

and finally rebase. This means that all commits that are not yet in upstream (and usually they never are) will be applied on top of the other branch

git rebase upstream/master

Easy. Happy coding!