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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github