Change git repository remote origin to upstream

All Posts

Change git repository remote origin to upstream

Updated: September 30, 2020 by Tony Alves

Sometimes you have a forked repository you cloned and want to change the origin to a new repository in your own organization. Here are the steps to accomplish this using git cli.

Check your remotes

$ git remote --verbose

You'll get some output similar to:

origin git@github.com:someorg/repo.git (fetch)
origin git@github.com:someorg/repo.git (push)

We'll want to change the origin to upstream, so we will setup upstream to the above repo and change the url of the origin.

Setup upstream:

$ git remote add upstream git@github.com:someorg/repo.git

Change origin:

$ git remote set-url origin git@github.com:myorg/myrepo.git

When we run git remote --verbose again, we get the following:

origin git@github.com:myorg/myrepo.git (fetch)
origin git@github.com:myorg/myrepo.git (push)
upstream git@github.com:someorg/repo.git (fetch)
upstream git@github.com:someorg/repo.git (push)

Done!

You can now git push to your new repository.

© Tony Alves