How to set git upstream

Trying to sync a fork that does not have an upstream repository can result in an error:

fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights

To resolve this error check the output of

$ git remote -v

Your output should look like this

UpStreamOwner (fetch)
UpStreamOwner (push)
origin (fetch)
origin (push)

What’s missing is the upstream.

To set the upstream for this fork run the following command:

$ git remote add upstream