How to Change Remote Origin in Git: A Step-by-Step Guide

In Git, origin is the default name for the remote repository your local project is connected to. But what if you need to change that origin—say, to push to a new GitHub repo, switch from HTTPS to SSH, or move to a different hosting provider?

In this post, you’ll learn how to view, change, and verify your Git remote origin using simple commands.


🧠 Why Change the Remote Origin?

You might need to update the origin if:

  • You cloned from the wrong repo.
  • You forked a project and now want to push to your own version.
  • You’re moving from GitHub to GitLab or vice versa.
  • You switched from HTTPS to SSH (or the other way around).

🔍 Step 1: Check the Current Origin

Before making changes, verify the current remote origin:

git remote -v

Output:

origin  https://github.com/old-user/old-repo.git (fetch)
origin  https://github.com/old-user/old-repo.git (push)

✏️ Step 2: Change the Remote Origin URL

Syntax:

git remote set-url origin <new-remote-url>

Example – Switching to a new GitHub repo:

git remote set-url origin https://github.com/your-username/new-repo.git

Or with SSH:

git remote set-url origin gi*@gi****.com:your-username/new-repo.git

✅ Step 3: Verify the Change

Check that the origin URL has been updated:

git remote -v

You should see the new URL:

origin  https://github.com/your-username/new-repo.git (fetch)
origin  https://github.com/your-username/new-repo.git (push)

➕ Optional: Add a New Remote Instead of Replacing

If you want to keep the existing origin and add another remote:

git remote add upstream https://github.com/original-owner/original-repo.git

This is useful when contributing to forks.


🧠 Best Practices

  • Use SSH for secure access (especially for pushing).
  • Use meaningful remote names (origin, upstream, production, etc.).
  • Always verify URLs before pushing to avoid mistakes.

🔁 Summary of Commands

TaskCommand
Check current remotegit remote -v
Change origin URLgit remote set-url origin <new-url>
Add a new remotegit remote add <name> <url>
Remove a remotegit remote remove <name>
Show detailed infogit remote show origin

🧩 Final Thoughts

Changing the Git remote origin is quick, but crucial—especially when you’re collaborating or reorganizing your repository structure. With just a couple of commands, you can seamlessly point your local repo to a new remote destination.

Sharing Is Caring:

Leave a Comment