data codes through eyeglasses

How to View and Change Remote Origins in Git

To change remote origin in Git, run git remote set-url origin <new-url>. To see where origin currently points, run git remote -v. The rest of this post covers the details: checking the result, switching between HTTPS and SSH, handling several remotes, and fixing the errors you’re most likely to hit.

Updated October 2026.

How to View the Remote Origin in Git

git remote -v

The -v (verbose) flag lists each remote with its fetch and push URLs. A typical result looks like this:

origin  https://github.com/you/project.git (fetch)
origin  https://github.com/you/project.git (push)

Two other commands are useful when you want something more specific:

  • git remote get-url origin prints only the URL, which is handy in scripts.
  • git remote show origin contacts the server and also shows the tracked branches and which local branches are set to push where.

How to Change the Remote Origin

Point origin at a new URL, for example after a repository moves, is renamed, or changes host:

git remote set-url origin https://github.com/you/new-project.git

Then check it worked:

git remote -v

Changing the URL doesn’t touch your commits or history. It only changes where Git sends and fetches. After changing it, run git fetch origin to confirm the new location is reachable.

Switch Between HTTPS and SSH

The most common reason to change a remote is to switch authentication. HTTPS asks for a token, SSH uses your key. To switch from HTTPS to SSH:

git remote set-url origin git@github.com:you/project.git

And back to HTTPS:

git remote set-url origin https://github.com/you/project.git

The same pattern works for GitLab, Bitbucket and self-hosted servers. Only the host and path change.

Work With More Than One Remote

A repository can have several remotes. “origin” is just the default name given when you clone. A common setup for a fork is origin for your fork and upstream for the original project. Name the remote you want to change:

git remote set-url upstream https://github.com/original-owner/project.git

You can set a different push URL for a remote without changing where it fetches from:

git remote set-url --push origin git@github.com:you/project.git

Add, Rename and Remove a Remote

  • Add a remote: git remote add upstream https://github.com/original-owner/project.git
  • Rename a remote: git remote rename origin old-origin
  • Remove a remote: git remote remove old-origin

If you’re starting a brand new local repository and want to connect it, use git remote add origin <url> and then git push -u origin main to push and set the upstream branch.

Fix Common Remote Errors

  • fatal: remote origin already exists: you tried git remote add origin when origin is already set. Use git remote set-url origin <url> instead, or remove it first.
  • fatal: No such remote 'origin': there is no remote with that name. Check the name with git remote -v, or add it with git remote add.
  • Permission denied (publickey): you switched to an SSH URL but your key isn’t added to the host. Add your public key to your GitHub or GitLab account, or switch back to HTTPS.
  • Repository not found: the URL is wrong, or your account doesn’t have access. Compare it with the URL shown on the repository’s page.

To check which remote branch your current branch tracks, run git branch -vv. If it points at the wrong place, set it with git branch --set-upstream-to=origin/main.

Quick Reference

  • View: git remote -v
  • Change URL: git remote set-url origin <new-url>
  • Add: git remote add <name> <url>
  • Rename: git remote rename <old> <new>
  • Remove: git remote remove <name>
  • Test the connection: git fetch origin