Skip to main content

How to switch a remote repo URL from HTTPS to SSH (and vice versa)

For my first post, I figured I could start with something really simple. I encountered this at work some time ago, but I forgot how to solve it after encountering it once again recently. Basically, I realized that (after not updating my website for awhile) I git cloned my repository using HTTPS instead of SSH onto my laptop. For the sake of convenience, I wanted to be able to do git pull, push and so on without having to validate my identification every time.

This is awfully simple, but I figured I might as well document this in case I forget it in the future, and hopefully this helps someone in need too. I referred to the GitHub documentation for the following tutorial.


When cloning repositories, you can choose whether to do it via HTTPS or SSH. A HTTPS type clone is creating a copy of a remote repo which you do not have automatic write access to, while an SSH type clone gives you the access to push your changes (as long as you have an SSH key set up) automatically. Hence, the URLs for the respective git clone types are in the following form:

  • HTTPS: https://github.com/USERNAME/REPOSITORY.git
  • SSH: git@github.com:USERNAME/REPOSITORY.git
As such, if you want to switch your remote repo's URL from HTTPS to SSH like I do, you will set your new URL to the SSH-type URL (and likewise you pick the HTTPS-type URL if you want SSH to HTTPS URL switch).

  1. On your terminal, go to local repository directory of which you wish to change the URL.

  2. Set the new remote URL:
    $ git remote set-url origin <yourEmail>@<domain>.com/<yourRepo>.git
    
    (You can obtain this URL by going to your GitHub account online, then going into your desired repo and clicking the 'Clone or Download' button. A pop up should appear and you should select 'Use SSH' to show the URL.)

  3. To display the updated remote URL, do:
    $ git remote -v
    

Comments