Git & GitHub
/Intermediate
HTTPS vs SSH
Definition
The two primary protocols used to connect a local Git repository to a remote GitHub repository.
Explain Like I'm New
- HTTPS: Requires you to use a Personal Access Token (PAT) every time you push, or requires a credential manager to remember it for you. Good for beginners. - SSH: Requires you to generate a digital key pair once. Afterward, authentication happens silently in the background. Good for professionals.
Real World Example
If your remote URL looks like `https://github.com/user/repo.git`, you are using HTTPS. If it looks like `git@github.com:user/repo.git`, you are using SSH.
Common Use Cases
- •Choosing an authentication method
Terminal Output
bash / terminal
# Check which protocol you are currently using:
$ git remote -v
# Output indicating HTTPS:
# origin https://github.com/facebook/react.git (push)
# Output indicating SSH:
# origin git@github.com:facebook/react.git (push)
# Switch from HTTPS to SSH
$ git remote set-url origin git@github.com:facebook/react.git
Interview Questions
basic
- Which protocol is recommended by GitHub for ease of use?
intermediate
- Can you switch a repository from HTTPS to SSH after it's already been cloned?