Graphite Reviewer is now Diamond

Git clone SSH vs HTTPS

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Cloning a Git repository is an essential task for developers, allowing them to copy an existing repository to their local environment. There are two main protocols for cloning repositories: SSH (Secure Shell) and HTTPS (Hypertext Transfer Protocol Secure). This guide breaks down the advantages, use cases, and steps for each protocol to help you decide the best method for your workflow.

SSH is a secure protocol used for authenticating and encrypting communication between your machine and the server. It offers enhanced security and convenience, especially for frequent Git users.

  • Enhanced security: SSH keys provide a more secure way to authenticate than passwords.
  • Credential-free operations: Once configured, you won't need to enter credentials for each Git operation.
  1. Generate an SSH key pair: Open a terminal and run the following command to create an SSH key pair:

    Terminal
    ssh-keygen -t ed25519 -C "your_email@example.com"

    Save the key in the default location or specify a custom path.

  2. Add the SSH key to GitHub:

    • Log in to your GitHub account and navigate to Settings > SSH and GPG keys > New SSH key.
    • Paste the contents of your public key (e.g., ~/.ssh/id_ed25519.pub) and click Add SSH Key.
  3. Configure the SSH agent: Start the SSH agent and add your private key:

    Terminal
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519
  4. Clone the repository: Find the repository's SSH URL (e.g., git@github.com:user/repository.git) and run:

    Terminal
    git clone git@github.com:user/repository.git
  • Test your connection: Use ssh -T git@github.com to verify the SSH setup.
  • Credential prompts: If prompted for a passphrase repeatedly, ensure the SSH agent is running and your key is added.
  • Custom key usage: Specify a custom key using ssh -i /path/to/private/key or set the GIT_SSH_COMMAND environment variable:
    Terminal
    export GIT_SSH_COMMAND="ssh -i /path/to/private/key"

HTTPS is widely used for cloning repositories due to its ease of setup and compatibility across networks. It’s a great option for users who prefer a simple configuration process.

  • Ease of use: Requires no additional setup beyond username/password or personal access tokens.
  • Network compatibility: Works through firewalls and proxy servers.
  1. Clone the repository: Copy the repository's HTTPS URL (e.g., https://github.com/user/repository.git) and run:

    Terminal
    git clone https://github.com/user/repository.git
  2. Manage credentials:

Choosing between SSH and HTTPS depends on your workflow requirements and setup preferences:

  • Choose SSH if:

    • You want secure, password-free operations.
    • You have access to set up SSH keys on the repository host.
  • Choose HTTPS if:

    • You want a straightforward setup without generating keys.
    • You’re working in environments that block SSH traffic (e.g., corporate networks with firewalls).

By following these steps, you'll master cloning repositories with both SSH and HTTPS, enabling smoother development workflows. For further optimization, consider tools like the Graphite CLI to automate and enhance your Git operations.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone