How Do I Change the URI (URL) for a Remote Git Repository?

Better Stack Team
Updated on June 24, 2024

To change the URI (URL) for a remote Git repository, you can use the git remote set-url command. Here's how you can do it:

Step 1: List Current Remote URLs

First, you may want to see the current URLs associated with your remote repository:

 
git remote -v

This command will list the names and URLs of all remote repositories. You'll see something like this:

 
origin  <https://github.com/username/repository.git> (fetch)
origin  <https://github.com/username/repository.git> (push)

Step 2: Change the URL

To change the URL of the remote repository, use the git remote set-url command followed by the remote name (e.g., origin) and the new URL:

 
git remote set-url origin <new-URL>

Replace <new-URL> with the new URL of the remote repository.

Step 3: Verify the Change

You can verify that the URL has been changed by listing the remote URLs again:

 
git remote -v

The new URL should now be displayed.

Note:

  • You can also use this command to change the URL for a different remote repository by specifying its name instead of origin.
  • Ensure that you have the necessary permissions to push to the new URL if you intend to push changes to the repository.
  • Changing the URL does not affect the commits or branches in the repository; it only updates the location from which you fetch and push changes.