How to Change a Git Remote's URL

By 

•

Updated on

•

4 min read

How to Change a Git Remote 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:

Terminal
git remote -v
output
origin	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:

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

For example, to change the origin remote to a new URL:

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

Verify that the URL was updated:

Terminal
git remote -v
output
origin	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:

txt
https://github.com/user/repo.git

An SSH remote URL looks like this:

txt
git@github.com:user/repo.git

To switch from HTTPS to SSH:

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

To switch from SSH to HTTPS:

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

SSH 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. You can use different URLs to access the same repository, for example, fetching over HTTPS and pushing over SSH.

To set a different push URL, use the --push flag:

Terminal
git remote set-url --push origin git@github.com:user/repo.git

Verify the result:

Terminal
git remote -v
output
origin	https://github.com/user/repo.git (fetch)
origin	git@github.com:user/repo.git (push)

The fetch URL still uses HTTPS, while the push URL uses SSH. Both point to the same repository. To fetch from an upstream repository and push to your own fork, use separate remotes such as upstream and origin instead.

Troubleshooting

error: No such remote 'origin' when running set-url
Use git remote -v and confirm the exact remote name. Remote names are case-sensitive.

error: remote origin already exists. when adding the remote
A remote named origin is already configured, so git remote add refuses to create it again. To point the existing remote at the new location, use git remote set-url origin <new-url> instead.

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.

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 switch between HTTPS and SSH, update a URL after a repository migration, or set separate fetch and push URLs. If you are moving to SSH and do not have a key yet, see our guide on generating SSH keys on Linux .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

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

View author page