Clone a GitHub repository via SSH.

To Nha Notes | Feb. 13, 2024, 5:46 p.m.

  1. Generate an SSH Key Pair:

    • Open a terminal (either Git Bash on Windows or a bash terminal on Linux).
    • Run the following command to generate an SSH key pair:
      ssh-keygen -t ed25519 -C "your_email@example.com"
      
    • Replace your_email@example.com with your actual email address.
    • Press Enter to confirm the default values (blank passphrase).
  2. Add the Public Key to GitHub:

    • Log in to your GitHub account.
    • Click your account image in the top right corner and select Settings.
    • Navigate to the SSH and GPG keys section.
    • Click the New SSH key button.
    • Provide a descriptive name for your SSH key and paste the public key you generated earlier.
  3. Clone the Repository:

    • Obtain the GitHub SSH URL for the repository you want to clone (usually in the format git@github.com:username/repository.git).
    • In your terminal, use the following command to clone the repository:
      git clone git@github.com:username/repository.git
      
    • Replace username with your GitHub username and repository with the repository name.