How to Change Git Remote URL to SSH from HTTPS

This guide walks you through changing your Git authentication method from HTTPS to SSH. Using SSH eliminates the need to enter a password each time you interact with a remote repository.

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:

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

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

# 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:

# 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:

# 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!


Recent Posts
Categories
Tags

Always On Availability Groups (AAG) (4) AWS (4) AWS Redshift (6) Database Admin (72) Database Backups & Recovery (14) Database Mirroring (2) Error Messages (5) Failover Cluster Instances (FCI) (1) Git Commands (6) Importing & Exporting Data (2) Linked Servers (3) Linux Administration (2) Logging & Monitoring (1) Microsoft Patching (2) MySQL (4) Postgres (6) PowerShell Scripts (2) SQL Certificates & Encryption (3) SQL Server Agent (5) SQL Server CDC (2) SQL Server Data Types (2) SQL Server Management Studio (SSMS) (17) SQL Server Networking (3) SQL Server on Linux (1) SQL Server Patching (2) SQL Server Performance Tuning (6) SQL Server Processes (SPIDs) (7) SQL Server Replication (2) SQL Server Scripts (13) SQL Server Security (4) SQL Server Storage (10) Windows Admin (20) Windows Authentication (2) Windows Automation (1) Windows Events (2) Windows Firewall (4) Windows Subsystem for Linux (WSL) (18)