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 https://github.com/UpStreamOwner/repository.git (fetch)
UpStreamOwner https://github.com/UpStreamOwner/repository.git (push)
origin https://github.com/yourName/repository.git (fetch)
origin https://github.com/yourName/repository.git (push)

What’s missing is the upstream.

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

$ git remote add upstream https://github.com/UpStreamOwner/repository.git
Advertisement