Jul 5, 2020
Per Djurner

Syncing a forked repository with Git

Something I run into every now and then is that I'll fork a project repository, fix a bug and submit a pull request. Some time goes by and I want to contribute something else to the project. My fork is now most likely out of date and I need to sync it with the project repository again.

In technical terms, what you need to do is configure a "remote" that points to the "upstream" repository. You can check the currently configured remote repository for your fork using this command:

git remote -v

Look for the "upstream" entries. If nothing is listed as "upstream", go ahead and configure a new remote upstream repository like this:

git remote add upstream https://github.com/OWNER/REPOSITORY.git

Once you've configured your remote you can do the following (from the master branch in your fork) every time you need to sync:

git fetch upstream (fetches code from the remote repository). git merge upstream/master (merges the changes from upstream/master into your local master branch).