Push & pull problemsAlways fixable

Change where your repository pushes to

How do I change the remote URL of a Git repository?

Short answer

git remote set-url origin <new-url> repoints an existing remote. It's a purely local change — nothing on either server is touched — so it's the safe way to switch between HTTPS and SSH, move to a new host, or fix a URL after renaming the repository.

quick fix
git remote set-url origin git@github.com:USER/REPO.git

Repoint origin — local only, nothing on the server changes

Does this match your situation?

  • You renamed the repository or moved it to a different organisation.
  • You want to switch from HTTPS to SSH (or back).
  • You're migrating from GitHub to GitLab, or to a self-hosted server.
  • You cloned someone's repo and now want to push to your own fork.

Step-by-step fix

  1. See what you have now

    Remotes have separate fetch and push URLs, so check both before changing anything.

    step 1
    git remote -v
    
  2. Point it somewhere new

    This rewrites the URL in .git/config. Nothing is uploaded, downloaded or deleted, and your commits are untouched.

    step 2
    git remote set-url origin git@github.com:USER/NEW-REPO.git
    git remote -v      # confirm
    git fetch origin   # verify it actually works
    
  3. Add a second remote instead of replacing

    When you want to push to two places — say a fork and the original — add another remote rather than replacing origin. This is the standard setup for contributing to open source.

    step 3
    git remote add upstream https://github.com/original/repo.git
    git remote -v
    git fetch upstream
    
  4. Rename or remove a remote

    Names are arbitrary; origin is only a convention. Renaming is safe and sometimes clearer, especially in a fork workflow.

    step 4
    git remote rename origin github
    git remote remove old-server
    
  5. Reconnect your branches if push complains

    After a URL change your branches usually keep tracking origin fine. If Git says there's no upstream, set it explicitly on the next push.

    step 5
    git push -u origin main
    

Why this works

A remote is nothing more than a named URL stored in .git/config, plus a set of remote-tracking refs cached locally. Changing the URL rewrites one line of a text file — that's why the operation is instant and completely reversible, and why it can't damage either the old or the new server. The commits live in your local object database regardless of which URL you happen to be pointing at.

How to stop it happening again

  • Use SSH URLs on machines you own so a password or token change never breaks them.
  • After transferring a repository on GitHub, update remotes in every clone — the old URL redirects, but not forever.
  • In a fork workflow, keep the convention: origin is your fork, upstream is the original.

Commands used in this guide

git remote

Manage the named URLs your repository syncs with.

git fetch

Download new commits from the remote without changing any of your files.

git push

Upload your commits to the remote repository.

git config

Read and write Git settings for one repo, your user, or the whole machine.

Still stuck?

Search the full command reference and every other rescue guide — there are 56 of them, covering everything from detached HEAD to force-push disasters.

Browse all guides →

Frequently asked questions

Does changing the remote URL affect my commits?

No. It edits one setting in .git/config. Your commits, branches and history are entirely local and unaffected, and neither the old nor the new server is contacted until you fetch or push.

How do I switch a repository from HTTPS to SSH?

git remote set-url origin git@github.com:USER/REPO.git. Confirm with git remote -v and test with git fetch. You'll need an SSH key registered on your account for it to authenticate.

What is the difference between origin and upstream?

They're just names. By convention origin is the repository you push to — typically your own fork — and upstream is the original project you fetch updates from. Git attaches no special meaning to either name.

Related rescue guides

← All Git Rescue guides