How to sync your fork with the parent repository

Jeremy Schuurmans - Oct 11 '19 - - Dev Community

Right now, my fork of dev.to displays this message:

This branch is 9 commits behind thepracticaldev:master

How do I update my fork so that it's the same as thepracticaldev:master?

cd into the directory of the cloned repo

cd code/open_source/dev.to

Running git remote -v will display the current remotes

git remote -v displays my fork as the only remotes

Add the parent repository as a new remote, specifying it as the upstream repository. In this example, we will run

git remote add upstream https://github.com/thepracticaldev/dev.to.git
Enter fullscreen mode Exit fullscreen mode

Verify with git remote -v

git remote -v shows thepracticaldev/dev.to as the upstream repository

Fetch the upstream repository with git fetch upstream

Alt Text

The commits that are different from my fork are now in separate branches in my local environment. Let's merge those. git merge upstream/master

Alt Text

Now my cloned repo looks just like the upstream repository.

NOTE: any changes made locally before the merge are preserved, so you don't have to worry about losing any of your work when you do this.

From now on, whenever I need to sync with the upstream repository, all I need to do is fetch and merge.

At this point, running git push will update the forked repo and display this message:

This branch is even with thepracticaldev:master

. . . . . . . . . . . . . .
Terabox Video Player