Git
HTTPS
SSH
Remote Repositories
Version Control

git clone with HTTPS or SSH remote?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Both HTTPS and SSH are valid ways to clone Git repositories, and each can be the better choice depending on environment and security policy. HTTPS is quick to start with and works well with token-based auth. SSH is usually better for frequent developer workflows because authentication is key-based and seamless after setup.

Clone with HTTPS

HTTPS remotes are straightforward and work in almost all network environments.

bash
git clone https://github.com/example-org/project.git

Modern platforms use personal access tokens instead of passwords. Credentials can be cached securely via credential managers, so repeated prompts are minimized.

HTTPS is often preferred in enterprise setups where SSH is restricted by network policy.

Clone with SSH

SSH remotes use public key authentication.

bash
git clone [email protected]:example-org/project.git

After key setup, pulls and pushes are usually frictionless. This is convenient for developers who interact with many repositories daily.

Basic key setup:

bash
ssh-keygen -t ed25519 -C "[email protected]"
cat ~/.ssh/id_ed25519.pub

Add the public key to your Git hosting account, then test connection:

Security and Operational Tradeoffs

HTTPS with tokens is secure when token scope and rotation are managed well. SSH offers strong security too, but private key handling must be disciplined. Neither method is automatically safer in all cases; security depends on operational controls.

In CI pipelines, HTTPS with short-lived tokens is often easier to automate. On developer laptops, SSH may reduce friction and improve day-to-day productivity.

Working Behind Corporate Proxies

Some corporate networks block outbound SSH on default port 22. HTTPS often works out of the box through proxy infrastructure, which can make onboarding easier for new team members.

If your provider supports SSH over alternate ports, you can still use SSH by configuring host entries in your SSH config file. Teams should document this clearly to avoid repeated setup issues.

Switching an Existing Remote

You can switch protocols without recloning.

bash
1# HTTPS to SSH
2git remote set-url origin [email protected]:example-org/project.git
3
4# SSH to HTTPS
5git remote set-url origin https://github.com/example-org/project.git
6
7git remote -v

This is useful when moving from a personal machine to a locked-down corporate environment.

Credential Rotation and Incident Response

No matter which protocol you choose, plan for key or token rotation. Keep revocation steps documented and automate regeneration where possible. During incidents, fast revocation and remote URL updates are more important than protocol preference.

Teams that rehearse credential rollover avoid prolonged outages when a token leaks or a private key is exposed.

Team Policy Recommendations

Standardize one default protocol per team and document fallback rules. Consistency reduces onboarding confusion and avoids failed pushes caused by mixed credential assumptions.

A pragmatic policy:

  • developer workstations: SSH
  • ephemeral CI runners: HTTPS tokens
  • restricted corporate networks: HTTPS as default

Also document one emergency fallback path in onboarding docs so engineers can keep working if key infrastructure or token minting systems are temporarily unavailable.

Common Pitfalls

  • Treating SSH setup as complete without verifying host access and key registration.
  • Using broad-scope HTTPS tokens can increase security exposure.
  • Sharing private SSH keys across machines is unsafe and breaks traceability.
  • Mixing protocol expectations in scripts can fail in different environments.
  • Forgetting to rotate compromised keys or tokens creates long-lived risk.

Summary

  • HTTPS and SSH both work for cloning and daily Git operations.
  • HTTPS is often easiest for constrained networks and token-based automation.
  • SSH is convenient for frequent developer push and pull workflows.
  • You can switch remotes with git remote set-url without recloning.
  • Choose protocol based on security policy, tooling, and operational context.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.