How to Change a Git Remote's URL

A Git remote is a reference that points to another copy of the repository, usually hosted on a remote server. When you git clone a repository
, Git automatically creates a remote named origin that points to the cloned URL. You can also add remotes manually
or remove remotes
you no longer need.
When a remote repository is migrated to another host or you need to switch from HTTPS to SSH, you can update the remote URL without removing and re-adding it.
This guide explains how to change the URL of a Git remote.
Changing the Remote URL
First, list the existing remotes and their URLs:
git remote -vorigin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)To change the URL, use the git remote set-url command followed by the remote name and the new URL:
git remote set-url <remote-name> <new-url>For example, to change the origin remote to a new URL:
git remote set-url origin git@github.com:user/repo.gitVerify that the URL was updated:
git remote -vorigin git@github.com:user/repo.git (fetch)
origin git@github.com:user/repo.git (push)The git remote set-url command updates the remote entry in the .git/config file. Using the command is preferred over editing the file manually.
Switching Between HTTPS and SSH
One of the most common reasons to change a remote URL is switching between HTTPS and SSH protocols.
An HTTPS remote URL looks like this:
https://github.com/user/repo.gitAn SSH remote URL looks like this:
git@github.com:user/repo.gitTo switch from HTTPS to SSH:
git remote set-url origin git@github.com:user/repo.gitTo switch from SSH to HTTPS:
git remote set-url origin https://github.com/user/repo.gitSSH is commonly preferred because it uses key-based authentication and works well for frequent CLI pushes. HTTPS also works well, especially when used with a credential manager or personal access token workflow.
Setting Separate Push and Fetch URLs
By default, a remote uses the same URL for both fetching and pushing. In some workflows, you may want to fetch from one URL and push to another.
To set a different push URL, use the --push flag:
git remote set-url --push origin git@github.com:user/fork.gitVerify the result:
git remote -vorigin https://github.com/user/repo.git (fetch)
origin git@github.com:user/fork.git (push)This is useful when you fetch from an upstream repository but push to your own fork.
Troubleshooting
fatal: No such remote when running set-url
Use git remote -v and confirm the exact remote name. Remote names are case-sensitive.
Push still goes to the old URL after set-url
Check whether a separate push URL is configured with git remote -v. If needed, update it with git remote set-url --push <name> <url>.
Authentication fails after switching from HTTPS to SSH
Make sure your SSH key is loaded and added to your Git hosting account. If you prefer token-based auth, switch back to HTTPS and use your credential manager.
Quick Reference
| Command | Description |
|---|---|
git remote -v | List remotes with URLs |
git remote set-url <name> <url> | Change a remote URL |
git remote set-url --push <name> <url> | Change only the push URL |
FAQ
Does changing the remote URL affect my local branches?
No. Changing the URL only updates where Git fetches from and pushes to. Your local branches, commits, and history remain unchanged.
When should I switch from HTTPS to SSH?
Switch to SSH when you want key-based authentication and a straightforward CLI workflow. HTTPS remains a good option when you use personal access tokens with a credential manager.
Can I have multiple remotes with different URLs?
Yes. Use git remote add <name> <url> to add additional remotes. This is common when working with forks — you might have origin pointing to your fork and upstream pointing to the original repository.
Conclusion
Use git remote set-url to change a remote URL. This is the standard way to switch between HTTPS and SSH, update a URL after a repository migration, or set separate fetch and push URLs.
If you have any questions, feel free to leave a comment below.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page