git remote set-url <remote> <url>

Change the URL of an existing Git remote.

This command is useful when a remote repository has moved or changed (for example after renaming a project or switching hosting providers), and it updates Git’s internal configuration so future fetches and pushes go to the new location.

This command tells Git to update the URL associated with an existing remote: <remote> is the name of the remote (commonly origin or upstream), and <url> is the new repository address (such as git@github.com:user/repo.git or https://github.com/user/repo.git); after running it, git fetch, git pull, and git push for that remote will use the new URL automatically. The remote subcommand targets Git’s stored remotes, set-url modifies the configured URL, <remote> selects which remote entry to change, and <url> replaces the previous value in the local repo’s config.

You can check the result with git remote -v to see the updated fetch and push URLs, or use variants like git remote set-url --push <remote> <url> to change only the push URL while keeping a different fetch URL, or git remote set-url --add <remote> <url> to add an additional URL for the same remote (useful for mirroring). Related commands include git remote add <remote> <url> for creating a brand-new remote, git remote remove <remote> for deleting one you no longer need, and git remote rename <old> <new> for renaming an existing remote while keeping its URLs.

Examples:

  • git remote set-url origin git@github.com:my-org/my-repo.git
  • git remote set-url upstream https://github.com/other-org/other-repo.git
Related commands

Welcome to GitExamples!

Sign in to gitexamples