git remote set-url changes the URL of an existing remote in your repository. You reach for it whenever you need to change a remote URL in Git, for example after you rename a repository, move it to a new account or organization, or want to switch origin from HTTPS to SSH. Because it edits the URL in place, git remote set-url is safer than removing and re-adding a remote, since your tracking branches and other settings stay intact.
This tutorial shows every common way to change a remote repository URL with real, tested output from git version 2.48.1.
git remote set-url - Quick Cheat Sheet
| Task | Command |
|---|---|
| View current remotes and URLs | git remote -v |
| Change a remote URL (e.g. origin) | git remote set-url origin <new-url> |
| Print the URL of a remote | git remote get-url origin |
| Change HTTPS to SSH | git remote set-url origin git@github.com:USER/REPO.git |
| Change SSH to HTTPS | git remote set-url origin https://github.com/USER/REPO.git |
| Add a new remote (keep the old one) | git remote add upstream <url> |
| Set a separate push URL | git remote set-url --push origin <push-url> |
| Add an extra push URL (push to two remotes) | git remote set-url --add --push origin <url> |
| List all push URLs of a remote | git remote get-url --all --push origin |
| Delete a push URL | git remote set-url --delete --push origin <url> |
| Rename a remote | git remote rename old new |
| Remove a remote | git remote remove name |
| Change URL via config | git config remote.origin.url <new-url> |
git remote set-url syntax
The command accepts three forms. This usage block is printed by Git itself when you call set-url without enough arguments:
usage: git remote set-url [--push] <name> <newurl> [<oldurl>]
or: git remote set-url --add <name> <newurl>
or: git remote set-url --delete <name> <url>
--[no-]push manipulate push URLs
--[no-]add add URL
--[no-]delete delete URLs<name>— the existing remote name, usuallyoriginorupstream.<newurl>— the new repository URL (HTTPS or SSH).--push— operate on the push URL instead of the fetch URL.--add/--delete— add or remove a URL rather than replacing it.
For the full option list, see the official git remote documentation.
Step 1: View the current remote URL
Before you change anything, list the configured remotes and their URLs with git remote -v:
$ git remote -v
origin https://github.com/olduser/myproject.git (fetch)
origin https://github.com/olduser/myproject.git (push)Every remote shows two lines: one for fetch (where Git pulls from) and one for push (where Git pushes to). Here the remote is named origin and points at an HTTPS URL.
Step 2: Change the remote URL with git remote set-url
To change the remote URL of origin, pass the remote name and the new URL. The command produces no output on success, so verify it afterwards with git remote -v:
$ git remote set-url origin https://github.com/newuser/myproject.git
$ git remote -v
origin https://github.com/newuser/myproject.git (fetch)
origin https://github.com/newuser/myproject.git (push)You can also print just the URL of a single remote with git remote get-url:
$ git remote get-url origin
https://github.com/newuser/myproject.gitThat is all it takes to change a Git remote URL. Your next git fetch, git pull, or git push automatically uses the new location.
Step 3: Confirm the new URL actually works
Changing the config is one thing; proving that pushes land at the new remote is another. The following is a fully reproducible sandbox that uses two local bare repositories (repo-1.git and repo-3.git) standing in for two GitHub remotes, so it runs without any network or credentials:
$ git remote get-url origin
/tmp/gturl/repo-1.git
$ git remote set-url origin /tmp/gturl/repo-3.git
$ git remote -v
origin /tmp/gturl/repo-3.git (fetch)
origin /tmp/gturl/repo-3.git (push)
$ git push -u origin main
To /tmp/gturl/repo-3.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.The commit now exists in the new remote, confirming the push followed the changed URL:
$ git --git-dir=/tmp/gturl/repo-3.git log --oneline
763e458 Add feature
09905b6 Initial commitIn your own project, simply replace the local paths with your real https://github.com/... or git@github.com:... URL.
Change remote URL from HTTPS to SSH (and back)
A very common reason to change a Git remote is switching the protocol. To move origin from HTTPS to an SSH URL:
$ git remote set-url origin git@github.com:newuser/myproject.git
$ git remote -v
origin git@github.com:newuser/myproject.git (fetch)
origin git@github.com:newuser/myproject.git (push)To switch back from SSH to HTTPS, run the same command with the HTTPS form:
$ git remote set-url origin https://github.com/newuser/myproject.git
$ git remote -v
origin https://github.com/newuser/myproject.git (fetch)
origin https://github.com/newuser/myproject.git (push)If you switch to SSH, make sure you have an SSH key added to your account first. If a push then fails with an authentication error, see could not read from remote repository for the fix.
Add a new remote instead of replacing it
Sometimes you want to keep the original remote and add a second one rather than change the existing URL. Use git remote add with a new name:
$ git remote add upstream https://github.com/org/myproject.git
$ git remote -v
origin https://github.com/newuser/myproject.git (fetch)
origin https://github.com/newuser/myproject.git (push)
upstream https://github.com/org/myproject.git (fetch)
upstream https://github.com/org/myproject.git (push)Now you have both origin and upstream. This is the recommended pattern for forks: origin is your fork and upstream is the original project.
Set a separate push URL
A remote can fetch from one URL and push to a different one. Set a dedicated push URL with --push. Notice the fetch and push lines now differ:
$ git remote set-url --push origin git@github.com:newuser/myproject.git
$ git remote -v
origin https://github.com/newuser/myproject.git (fetch)
origin git@github.com:newuser/myproject.git (push)Push to two remotes at once
To mirror every push to a second repository, add an extra push URL with --add --push. A single git push then writes to both:
$ git remote set-url --add --push origin git@gitlab.com:newuser/myproject.git
$ git remote -v
origin https://github.com/newuser/myproject.git (fetch)
origin git@github.com:newuser/myproject.git (push)
origin git@gitlab.com:newuser/myproject.git (push)List every push URL on the remote with git remote get-url --all --push:
$ git remote get-url --all --push origin
git@github.com:newuser/myproject.git
git@gitlab.com:newuser/myproject.gitDelete a push URL
Remove a single push URL with --delete --push:
$ git remote set-url --delete --push origin git@gitlab.com:newuser/myproject.git
$ git remote -v
origin https://github.com/newuser/myproject.git (fetch)
origin git@github.com:newuser/myproject.git (push)Rename and remove a remote
You can rename a remote (and Git rewrites its tracking refs for you):
$ git remote rename upstream backup
$ git remote -v
backup https://github.com/org/myproject.git (fetch)
backup https://github.com/org/myproject.git (push)
origin git@github.com:newuser/myproject.git (fetch)
origin git@github.com:newuser/myproject.git (push)To remove a remote entirely:
$ git remote remove backup
$ git remote -v
origin git@github.com:newuser/myproject.git (fetch)
origin git@github.com:newuser/myproject.git (push)Change a remote URL via git config
git remote set-url is just a friendly wrapper around the remote settings stored in .git/config. You can update the remote URL directly with git config:
git config remote.origin.url https://github.com/newuser/myproject.gitTo inspect what Git has stored for the remote:
$ git config --get-regexp '^remote\.origin\.'
remote.origin.url https://github.com/newuser/myproject.git
remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
remote.origin.pushurl git@github.com:newuser/myproject.gitNote that a separate push URL is stored as remote.origin.pushurl. You can also open .git/config in an editor, find the [remote "origin"] block, and edit the url = line by hand — git remote set-url simply does this for you safely.
Fix "remote: This repository moved. Please use the new location"
When you rename a GitHub repository or transfer it to another account or organization, GitHub redirects the old URL but does not update your local configuration. A push still works but prints a warning like:
remote: This repository moved. Please use the new location: remote: https://github.com/newowner/newname.git
To stop the warning and point your local repo at the real location, copy the new URL from the message and run git remote set-url:
git remote set-url origin https://github.com/newowner/newname.gitVerify the change with git remote -v, and the "repository moved" message disappears on the next push.
Common git remote set-url errors and fixes
error: No such remote
$ git remote set-url nosuch https://github.com/newuser/myproject.git
error: No such remote 'nosuch'The remote name does not exist. Run git remote -v to find the correct name (it is almost always origin) and retry.
error: remote origin already exists
$ git remote add origin https://github.com/x/y.git
error: remote origin already exists.This happens when you try to git remote add a remote that is already configured. To change its URL instead, use git remote set-url origin <new-url> rather than adding it again.
usage error from set-url
If you forget the new URL, Git prints the usage block instead of changing anything:
$ git remote set-url origin
usage: git remote set-url [--push] <name> <newurl> [<oldurl>]
or: git remote set-url --add <name> <newurl>
or: git remote set-url --delete <name> <url>Supply both the remote name and the new URL to fix it.
set-url vs remote add vs remove + add
| You want to... | Use this |
|---|---|
| Move an existing remote to a new URL | git remote set-url origin <new-url> |
| Keep the old remote and add another | git remote add <name> <url> |
| Completely reset a broken remote | git remote remove then git remote add |
| Just rename the remote, keep the URL | git remote rename old new |
In almost all cases git remote set-url is the right choice for changing a remote origin URL, because it preserves your upstream tracking configuration.
Frequently Asked Questions
1. What does git remote set-url do?
2. How do I change the remote URL of origin?
3. How do I change a Git remote URL from HTTPS to SSH?
4. How do I fix remote: This repository moved. Please use the new location?
5. What is the difference between git remote set-url and git remote add?
6. Why do I get error: No such remote?
7. How do I push to two remotes at once?
8. Can I change the remote URL without git remote set-url?
Summary
git remote set-url is the standard way to change a remote repository URL in Git. List your remotes with git remote -v, run git remote set-url origin <new-url> to point origin at the new location, and verify with git remote -v or git remote get-url origin. The same command switches between HTTPS and SSH, sets separate or additional push URLs, and fixes the "this repository moved" warning after a repo is renamed or transferred. Because it edits the URL in place, it keeps your tracking branches intact and is safer than removing and re-adding a remote.

