Change Git Remote URL from HTTPS to SSH (git remote set-url)

To change a Git remote from HTTPS to SSH, point origin at the SSH URL with git remote set-url, then check it:

Bash
# switch origin to the SSH URL (copy yours from the repo's Clone button)
git remote set-url origin git@github.com:USER/REPO.git

# confirm: fetch and push should both show git@...
git remote -v

Nothing is re-cloned and no history changes; only the address Git uses for origin. Once SSH keys are in place you stop getting username and password (or token) prompts.

Before proceeding, ensure you have SSH keys set up. If you haven’t done this yet, check out my guide on setting up SSH keys in Ubuntu WSL.

Contents:
1.
Check Current Git Remote URL
2. Change Git from HTTPS to SSH
3. Test the Connection

Steps to Change Git Authentication from HTTPS to SSH

Check Your Current Git Remote URL

If your repository is not already cloned, we use the following command to clone it via HTTPS:

Code
# Clone repo using HTTPS
git clone https://your-repo-url.git
Git Clone Repo HTTPS

Now, let’s check the current Git remote URL:

Shell
# Check the remote Git URL
git remote get-url origin
Git Remote Get-URL Origin

If the returned URL starts with https://, it confirms that your repository is using HTTPS authentication.

Change Git from HTTPS to SSH

Switching to SSH authentication allows more seamless interactions with Git repos without having the repeated password prompts.

Step 1: Retrieve the SSH URL
Head over to your repository hosting service (e.g., GitHub, GitLab, Bitbucket) and locate the SSH URL for your repository. For this demo I’m using Bitbucket. It’s all more or less the same, and you should be able to find the similar drop-down menu below.

Step 2: Navigate to your Git repository link and select SSH

Bitbucket Remote URL

Step 3: Update the Git Remote URL
Run the following commands to update the remote URL from HTTPS to SSH, and to confirm that the remote URL has been updated successfully:

Code
# Set remote URL to SSH
git remote set-url origin git@your-repo-provider.com:your-repo.git

# Check the updated remote Git URL
git remote get-url origin
Git Set URL to SSH

The output should now start with git@, indicating that SSH authentication is in use.

Test the Connection

To ensure everything is working correctly, try fetching the latest changes from your repository:

Code
# Test SSH connection
git fetch

If no authentication prompts appear and the command executes successfully, your Git repository is now using SSH authentication!


Conclusion

Switching from HTTPS to SSH authentication in Git improves security and streamlines the workflow by eliminating repeated password prompts. Once configured, SSH makes managing repositories easier. If you need help setting up SSH keys, refer to my detailed guide on setting up SSH on Ubuntu WSL.

For more random tips on using Git (mostly on Windows), check out my blog tag Git Commands!


Related

If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.