0
0
GitHow-ToBeginner · 3 min read

How to Change Remote URL in Git: Simple Steps

Use the git remote set-url command followed by the remote name (usually origin) and the new URL to change the remote URL in Git. For example, git remote set-url origin https://new.url/repo.git updates the remote URL.
📐

Syntax

The command to change a remote URL in Git is:

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

Here, <remote-name> is usually origin, the default remote name, and <new-url> is the new repository URL you want to use.

bash
git remote set-url origin https://new.url/repo.git
💻

Example

This example shows how to change the remote URL from an old GitHub repository to a new one.

bash
git remote -v
# Output shows current remotes

# Change the remote URL
 git remote set-url origin https://github.com/user/new-repo.git

# Verify the change
 git remote -v
Output
origin git@github.com:user/old-repo.git (fetch) origin git@github.com:user/old-repo.git (push) # After change origin https://github.com/user/new-repo.git (fetch) origin https://github.com/user/new-repo.git (push)
⚠️

Common Pitfalls

Common mistakes when changing remote URLs include:

  • Using the wrong remote name instead of origin.
  • Typing the URL incorrectly, causing connection errors.
  • Not verifying the change with git remote -v.

Always double-check the URL and remote name before running the command.

bash
git remote set-url origin git@github.com:user/new-repo.git
# Wrong remote name example
# git remote set-url orign https://github.com/user/new-repo.git  # typo in 'origin'

# Correct verification
 git remote -v
📊

Quick Reference

Summary tips for changing Git remote URLs:

  • Default remote name is usually origin.
  • Use git remote set-url to update the URL.
  • Verify changes with git remote -v.
  • Use HTTPS or SSH URLs depending on your access method.

Key Takeaways

Use git remote set-url origin <new-url> to change the remote URL.
Always verify the change with git remote -v to avoid mistakes.
The remote name is usually origin, but check if different.
Ensure the new URL is correct and accessible to prevent connection errors.