Git

How to change a remote repository’s URL

To change the URL of a remote repository in Git, you can use the git remote set-url command. Here’s how to do it step by step:

Step 1. Check the current remote url.

Run the following command to see the current remote URL:

git remote -v

This will show you the current remote repositories (e.g., origin) and their associated URLs for fetch and push.

Step 2. Set the new remote URL

Use the git remote set-url command to update the remote URL:

git remote set-url <remote-name> <new-url>

Replace <remote-name> with the name of your remote (e.g., origin).
Replace <new-url> with the new repository URL.

For example:

git remote set-url origin https://github.com/username/new-repo.git

Step 3. Verify the change

Confirm the new URL has been set by running:

git remote -v

You should see the updated URL listed.

Step 4. Test the new URL

    Test the connection with the new remote URL by running:

    git fetch

    If the fetch is successful, the new remote URL is correctly set.