Change Git Remote URL to SSH from HTTPS

This post is a guide on how to change Git from using SSH to HTTPS for authentication.

Using SSH for your version control system is more efficient as we do not have to enter a password every time we need to contact the remote repository.

You should have SSH keys already setup before proceeding with the steps below. If you don’t yet have SSH keys setup, have a look at my other post which will help guide you through creating SSH keys on an Ubuntu WSL instance – Setup SSH on Ubuntu (WSL)

The following steps demo changing SSH to HTTPS:
# Check Current Git URL
# Change Git from HTTPS to SSH auth

Check Current Git URL

I’m going to clone a git repo using HTTPS to set this demo up –

Git Clone Repo HTTPS

Now that we are authenticating to Git using HTTPS, we should check the Git remote URL.

The following command will return your remote Git URL –

# Check current remote git url
git remote get-url origin

If the returned value starts with HTTPS, that means we are using HTTPS to auth to Git, not SSH.

As mentioned above, we want to move from this to SSH so we can avoid entering a password everytime we need to authenticate to the Git system. Lets make the move over to SSH auth!

Change Git from HTTPS to SSH Auth

We are now going to change from HTTPS to SSH in Git.

Navigate to your Git repository link and select SSH. For this demo I’m using the Bitbucket version control system. It’s all the same though and you should be able to find the similar drop-down menu below.

Bitbucket Remote URL

Run the following command to set the new Git URL and make the move to SSH auth –

# Set remote URL for Git (to SSH)
git remote set-url origin <ssh-url>
Git Set URL to SSH

The above screenshot shows various commands to verify this works as expected, including git log –online which is great for checking recent repo commits with a condensed output.