How do I change the URI URL for a remote Git repository?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Changing a Git remote URL is a normal maintenance task when a repository moves, an organization is renamed, or a team switches from HTTPS to SSH. The key is to update the remote cleanly, then verify both fetch and push behavior so the repository does not quietly point at the wrong place.
Inspect the Current Remote First
Before changing anything, check what the repository is using now:
git remote -v shows fetch and push URLs for each remote. git branch -vv shows what each local branch is tracking.
This matters because many repositories have more than one remote, usually something like origin and upstream. You need to update the correct one.
Change the URL with git remote set-url
The standard command is:
For HTTPS, the command looks the same except for the URL:
Then verify the result:
This does not change your commit history, branches, or working tree. It only changes where that remote points.
Fetch and Push URLs Can Be Different
Git allows separate fetch and push targets. That is useful when a team fetches from a read-only mirror but pushes to the canonical repository.
Set them separately like this:
Check them with:
If you do not intentionally need separate endpoints, keep them the same to reduce confusion.
Test the New Configuration
Configuration output is not enough. Run a real network operation after the change:
If the remote is writable and you want to verify push access too, push a temporary branch:
If that succeeds, remove it:
That confirms the new remote works for both reading and writing.
Switching from HTTPS to SSH
Many teams eventually move from HTTPS to SSH because it avoids repeated username and token prompts once keys are configured correctly.
A typical SSH migration looks like this:
The ssh -T step matters. If SSH authentication is not working, changing the Git URL alone will not fix push failures.
Multi-Remote Repositories
If you are working in a fork-based workflow, you may see something like:
Example output:
In that case, changing origin and changing upstream are very different operations. Be deliberate about which remote you are modifying.
Submodules and Automation
A remote URL change can also affect:
- CI jobs that run
git fetch - deployment scripts
- submodule URLs in
.gitmodules
If submodules are involved, update and sync them too:
Otherwise the top-level repository may be correct while nested repositories still point to the old host.
Common Pitfalls
The most common mistake is updating the wrong remote. Always inspect git remote -v before changing anything.
Another issue is assuming that a new URL also fixes authentication. HTTPS credentials, SSH keys, and host permissions are separate concerns.
People also forget that fetch and push URLs can differ. If pushes still go to the wrong place after a change, check the push URL specifically.
Finally, do not skip the real fetch and push test. A typo in the remote string may not be obvious until you actually hit the network.
Summary
- Use
git remote set-urlto change a remote without recloning the repository. - Verify whether you are updating
origin,upstream, or another remote. - Check both fetch and push URLs after the change.
- Test the new configuration with a real
fetch, and a temporarypushif appropriate. - If the repository uses SSH, confirm your SSH setup before blaming Git.

