You change a Git remote's URL with git remote set-url, run from inside the repository. The command takes two arguments: the remote name (almost always origin) and the new URL. If the remote was cloned over HTTPS and you now need SSH, or the host moved from one domain to another, this is the same one-line fix. Verify it worked with git remote -v. Every fetch and push after that goes to the new address, and branches already tracking the remote keep their upstream link because the remote's name hasn't changed.

What follows covers the exact syntax, how to read the old URL before you overwrite it, what to do when the remote has a non-default name or several URLs, and how to tell a URL problem apart from an authentication problem when the push still fails afterward.

Read the current URL before you touch anything

Changing a URL starts with knowing what you're changing it from. Run:

The output lists each remote with its fetch and push URLs side by side. For a typical clone you'll see four lines: origin fetch, origin push, and the same pair for any additional remotes. If the fetch and push URLs differ, that's deliberate in some setups, and set-url without a flag rewrites only the fetch URL, which is a trap worth knowing about before you start.

Confirm you're in the right repository first. git rev-parse --show-toplevel prints the root of the working tree Git is operating on, which matters if you keep several checkouts open in different terminal tabs. Running set-url in the wrong repository silently changes the wrong project's remote.

There's no confirmation prompt and no undo. git remote set-url overwrites immediately. If you might want the old value back, copy it into your notes or a scratch file first. Restoring it is just another set-url call with the old string, but only if you still have that string.

The command itself: syntax and the two arguments

The full form is:

Replace with the remote's name and with the destination. Note there is no -- separator and no equals sign. A very common early mistake is writing git remote set-url origin=..., which Git rejects with a usage error because it reads the whole token as the remote name. The space between the two arguments is required.

Three worked examples, each a complete command:

HTTPS to HTTPS, new host: git remote set-url origin HTTPS to SSH: git remote set-url origin [email protected]:owner/repo.git SSH to HTTPS: git remote set-url origin

Quote the URL if it contains characters your shell treats specially, such as & or ? in some query strings. Double quotes are enough on Bash, Zsh, and PowerShell.

Success is silent. set-url prints nothing on a valid change. That silence is the expected result, not a failure. The very next check is git remote -v, which should now show the new address on both the fetch and push lines.

Worked example: moving a repository from HTTPS to SSH

Suppose git remote -v shows:

You've decided to authenticate with a key instead of a token, so the new URL is the SCP-like form:

Then verify:

Now test the connection with a real, read-only operation rather than trusting the display: git fetch origin. A successful fetch prints the ref updates or nothing if you're already current. If it hangs or asks for a password you didn't expect, the problem is authentication on the new URL, not the URL itself. Test SSH separately with ssh -T [email protected], which on a correctly configured key prints a greeting naming your account and exits. That single test separates "wrong address" from "right address, wrong credentials" faster than any Git command.

One subtlety: the SCP-like syntax git@host:owner/repo.git and the full ssh://git@host/owner/repo.git form are both valid, but the first uses a colon before the path and the second uses a slash. Mixing them, such as git@host/owner/repo.git, produces a URL Git cannot parse. If fetch fails with "does not appear to be a git repository," check that separator first.

Changing only the push URL, or running separate fetch and push destinations

A remote can hold two different URLs: one for fetch, one for push. This is genuinely useful when you pull from an upstream project but push to your own fork. The flags are --push and --add.

git remote set-url --push origin [email protected]:your-name/repo.git changes only the push URL and leaves fetch pointing at the original. git remote -v will then show different addresses on the fetch and push lines, which is the intended state, not a bug.

git remote set-url --add --push origin appends an additional push URL rather than replacing the existing one. A remote can carry several push URLs, and a push goes to all of them. That's occasionally used for mirroring to a second host. To remove an extra push URL, use git remote set-url --delete --push origin ; the plain set-url cannot delete, it only overwrites.

If you run set-url with no flag on a remote that had distinct fetch and push URLs, you rewrite the fetch URL and leave push alone. The display afterward looks inconsistent until you realize the push line still shows the old address. Decide which of the two you meant to change before running the command.

When the remote isn't called origin

The name is whatever you or the tool that created the repository chose. git remote with no arguments lists the names, one per line. Common alternatives are upstream, fork, or a vendor's name.

Rename is a separate operation from URL change, and the commands are easy to confuse:

git remote rename old new renames the remote and updates the tracking configuration for branches that used it. git remote set-url new changes where an existing remote points.

Renaming is safe for tracking branches because Git rewrites the remote and branch settings that reference the old name. Changing a URL doesn't affect tracking at all, which is why it's the lighter operation. If you renamed a remote and later want the old name back, rename again; there's no separate restore command.

Other ways to change the URL, and when each is appropriate

set-url is the surgical option. Three alternatives exist, and each suits a different situation.

Editing .git/config directly. The remote lives in the repository's config file under a [remote "origin"] section with a url = ... line. You can edit it in any text editor and the change takes effect on the next Git command, no restart needed. Use this when you're already in the file for other reasons, or when a script generates the config. The risk is syntax: YAML-style indentation isn't required, but a malformed section header breaks the whole remote. git config --get remote.origin.url reads the value back without guessing at the file's layout.

git config remote.origin.url . This writes the same key through Git's own config machinery, which is slightly safer than hand-editing if you're scripting. It's the underlying operation set-url performs, minus the argument validation and the --push/--add conveniences.

Re-adding the remote. git remote remove origin followed by git remote add origin rebuilds the remote from scratch. This drops any push URLs and any remote-tracking configuration attached to the name, so it's a heavier reset. Reach for it when the remote's configuration is genuinely tangled and you want a clean slate, not for a routine address change.

For most readers the first command in this article is the right one. The alternatives matter when you're automating the change or repairing a remote that has accumulated conflicting entries.

Verifying the change and handling a failed push

A URL change is verified at two levels, and both are worth doing because they fail for different reasons.

The configuration level is git remote -v. Both fetch and push lines should show the new address. If a line still shows the old one, you either changed only the push URL or you ran the command against a different remote name.

The connection level is a real transfer. git fetch origin proves read access; git push proves write access. These can differ: a repository can be publicly readable over HTTPS while your account lacks push permission. A successful fetch followed by a rejected push points at permissions, not the URL.

Common failure symptoms and their likely causes:

"Repository not found" or "does not appear to be a git repository." The path or host in the URL is wrong, or the URL uses the wrong separator between host and path. Recheck the exact string, including the .git suffix and any subgroup or organization segment. Authentication prompt or "Permission denied (publickey)." The address resolved fine but credentials failed. Test with ssh -T git@host for SSH, or confirm your token still has access for HTTPS. This is not a set-url problem. Push rejected as non-fast-forward. The URL changed correctly and you're pushing to a branch that has diverged. Fetch and reconcile before pushing again; the remote address is not the cause. Fetch succeeds but pushes go to the wrong place. Almost always a leftover push URL from an earlier --push configuration. Run git remote -v and look specifically at the push line.

If an SSH connection fails after a host change, the host's key may not be in your known_hosts file, and the first connection will ask you to confirm the fingerprint. Confirm it only against the fingerprint the host publishes in its own documentation. Accepting an unverified key on a first connection is the one step in this workflow where a moment of care matters.

What the URL change does not affect

It's worth being explicit about the boundaries, because a mistaken expectation here causes wasted debugging. Changing the remote URL does not rewrite your commit history, does not alter branch names, and does not touch files in the working tree. It does not change the author identity on future commits, which comes from user.name and user.email in the config, not the remote.

It also doesn't migrate the remote-tracking branches themselves. After a git fetch against the new URL, the remote-tracking references update normally, but any branch that existed only on the old remote and not on the new one will appear to vanish. That's not data loss in your local repository; it reflects what the new remote actually contains.

Finally, the change applies only to the repository where you ran the command. Clones are independent, so a colleague's checkout keeps pointing at the old address until they run the same command. If a team is moving a host, that's a one-line instruction to share, and it's often the fastest way to prevent a morning of confused pushes.

Questions that come up after the change

Does changing the remote URL break my branch tracking? No. Tracking is stored by remote name, and the name is unchanged. git pull and git push on a tracking branch keep working against the new address.

Can I change the URL for all my repositories at once? Not with a single set-url call. Each repository stores its own remote configuration. The only cross-repository mechanism is url..insteadOf, a Git config rewrite rule that substitutes a prefix globally, which is a different tool from changing a stored remote and is overkill for a one-off move.

What's the difference between git remote set-url and git remote add? add creates a remote that didn't exist; set-url points an existing remote somewhere new. Using add with a name that already exists fails with "remote already exists," which is Git telling you to use set-url instead.

I ran the command and it printed nothing. Did it work? Yes, silence is success. Confirm with git remote -v.

Worth remembering

The whole operation is one command plus one check: git remote set-url origin , then git remote -v to confirm both lines changed. The complications are all in the edges: a non-default remote name, a separate push URL left over from a fork workflow, or a failure that turns out to be authentication rather than addressing. Knowing which of those you're facing turns a confusing rejection into a two-minute fix.