How to change remote URL in Git

Changing the remote URL is necessary when switching between HTTPS and SSH, migrating repositories, or updating repository locations. As the creator of CoreUI with 25 years of Git experience managing distributed teams, I regularly update remote URLs when moving projects or changing authentication methods.

The most straightforward command is git remote set-url origin new-url.

Direct Answer

Update the remote URL with set-url:

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

View Current Remote URL

Check existing remote URLs:

git remote -v

Output:

origin  https://github.com/user/old-repo.git (fetch)
origin  https://github.com/user/old-repo.git (push)

Change HTTPS to SSH

Switch from HTTPS to SSH authentication:

git remote set-url origin [email protected]:user/repo.git

Change SSH to HTTPS

Switch from SSH to HTTPS:

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

Change Specific Remote

Update a named remote (not origin):

git remote set-url upstream https://github.com/original/repo.git

Add New Remote

Add an additional remote:

git remote add backup https://github.com/user/backup-repo.git

Remove Remote

Delete a remote:

git remote remove backup

Rename Remote

Change remote name:

git remote rename origin old-origin
git remote rename new-origin origin

Update Multiple Remotes

For push to multiple repositories:

git remote set-url --add --push origin https://github.com/user/repo1.git
git remote set-url --add --push origin https://github.com/user/repo2.git

Now git push origin pushes to both URLs.

Verify Changes

Confirm the URL was updated:

git remote -v

Expected output:

origin  https://github.com/user/new-repo.git (fetch)
origin  https://github.com/user/new-repo.git (push)

Update All Remotes

If you have multiple remotes to update:

git remote set-url origin https://github.com/user/new-repo.git
git remote set-url upstream https://github.com/original/new-repo.git

Explanation

The remote URL determines where Git fetches from and pushes to. When you run git remote set-url, Git updates the URL in .git/config. The origin remote is the default remote created when you clone a repository, but you can have multiple remotes with different names.

Best Practice Note

This is the same remote management workflow we use in CoreUI’s repositories when migrating between hosting providers or switching authentication methods. Always verify the URL with git remote -v after changing it, and test with a fetch before pushing to ensure the URL is correct.

For related Git operations, check out how to set upstream branch in Git and how to prune remote branches in Git.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author