Understand the differences between SSH and HTTPS on GitHub—learn key setup, cloning, switching protocols, and comparing security versus ease-of-use.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Understanding SSH and HTTPS on GitHub
When you interact with GitHub repositories, you can choose between two transport protocols for pushing and pulling code: HTTPS or SSH. Both protocols encrypt data in transit, but they differ in authentication methods and setup complexity.
HTTPS
SSH
Step 2: Cloning a Repository via HTTPS
To clone a GitHub repository over HTTPS, you simply copy the HTTPS URL from the repository page and run:
git clone https://github.com/USERNAME/REPOSITORY.git
You’ll be prompted for your GitHub credentials (username and password or personal access token) when you push or pull.
If you want Git to remember your credentials, configure a credential helper:
git config --global credential.helper cache
# Or on macOS:
git config --global credential.helper osxkeychain
# Or on Windows:
git config --global credential.helper wincred
Step 3: Setting Up and Cloning via SSH
SSH requires generating a key pair on your local machine and adding the public key to your GitHub account.
Generate an SSH key (if you don’t already have one):
ssh-keygen -t ed25519 -C "your\[email protected]"
# If ed25519 isn’t supported, use:
ssh-keygen -t rsa -b 4096 -C "your\[email protected]"
This creates two files by default:
• ~/.ssh/id_ed25519 (private key)
• ~/.ssh/id_ed25519.pub (public key)
Start the SSH agent and add your private key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id\_ed25519
Copy your public key to the clipboard:
# macOS:
pbcopy < ~/.ssh/id\_ed25519.pub
# Linux:
xclip -sel clip < ~/.ssh/id\_ed25519.pub
# Windows (Git Bash):
cat ~/.ssh/id\_ed25519.pub | clip
Log into GitHub, go to Settings → SSH and GPG keys → New SSH key, then paste and save your key.
Now clone using the SSH URL:
git clone [email protected]:USERNAME/REPOSITORY.git
You should be able to push and pull without entering a password each time.
Step 4: Switching an Existing Repository Between HTTPS and SSH
If you already cloned a repository via one protocol and want to switch:
Check your current remote URL:
git remote -v
Switch from HTTPS to SSH:
git remote set-url origin [email protected]:USERNAME/REPOSITORY.git
Switch from SSH to HTTPS:
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
Verify the change:
git remote -v
Step 5: Comparing SSH vs HTTPS in GitHub
Choose the protocol that best fits your security requirements and workflow preferences.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.