The git remote set-url command changes an existing remote repository URL.

The git remote set-url command takes two arguments:

  • An existing remote name, for example, origin
  • A new URL for the remote, for example:
    • https://github.com/user/repo2.git if you're updating to use HTTPS
    • git@github.com:user/repo2.git if you're updating to use SSH

For example:

git remote -v
# View existing remotes
# origin  https://github.com/user/repo.git (fetch)
# origin  https://github.com/user/repo.git (push)

git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL

git remote -v
# Verify new remote URL
# origin  https://github.com/user/repo2.git (fetch)
# origin  https://github.com/user/repo2.git (push)

Troubleshooting

You may encounter these errors when trying to changing a remote.

No such remote '[name]'

This error means that the remote you tried to change doesn't exist:

git remote set-url sofake https://github.com/octocat/Spoon-Knife
# fatal: No such remote 'sofake'

Check that you've correctly typed the remote name.

Further reading