Skip to content

Instantly share code, notes, and snippets.

@darnocer
Last active April 20, 2023 17:37
Show Gist options
  • Save darnocer/24004c47e3313d00ed9f420bb2f8ead8 to your computer and use it in GitHub Desktop.
Save darnocer/24004c47e3313d00ed9f420bb2f8ead8 to your computer and use it in GitHub Desktop.
Connecting to Remote Repositories

How to update the remote repository

If you have a local repository already connected to a remote repository (Github) and you want to update the connection to a different remote repository.

Check remote repo

Verify the repo it is already connected to that you want to change

git remote -v

Update to a different remote repo

Grab the URL from the new repo you want to connect to

git remote set-url origin git@github:USERNAME/REPO.git

Example

git remote set-url origin git@github:darnocer/README-Generator.git

Connect to a remote repo

If you run into this error:

> error: No such remote 'origin'

Connect to the repo first:

git remote add origin git@github:USERNAME/REPO.git

Force push changes

If the new remote repo is empty, overwrite it with your local repo contents:

git push -f origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment