Clone Repository
This document will guide developers to clone the repository.
Getting Startedβ
Most of our repositories are hosted on GitHub as private repositories. Unlike public repositories, private repositories require authentication to clone. We will go through the steps to clone a private repository using both CLI and Github Desktop.
You can use both SSH and Personal Access Token (PAT) to authenticate. But SSH is simpler and easy to use.
Using Personal Access Tokenβ
Creating a Personal Access Tokenβ
This document is derived from the GitHub Official Documentation, page Creating a personal access token.
Verify your email address, if it hasn't been verified yet.
In the upper-right corner of any page, click your profile photo, then click Settings.
In the left sidebar, click Developer settings.
In the left sidebar, under Personal access tokens, click Tokens (classic).
Select Generate new token, then click Generate new token (classic).
Give your token a descriptive name.
To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker.
Select the scopes you'd like to grant this token. To use your token to access repositories from the command line, select repo. A token with no assigned scopes can only access public information. For more information, see "Available scopes".
Click Generate token.
To use your token to access resources owned by an organization that uses SAML single sign-on, authorize the token. For more information, see "Authorizing a personal access token for use with SAML single sign-on" in the GitHub Enterprise Cloud documentation.
Clone the repository using CLIβ
Open the terminal and navigate to the directory where you want to clone the repository.
Clone with URL, it's just like cloning a public repository, but you need to add your PAT to the URL. For example:
git clone https://<your-username>:<your-pat>@github.com/<your-username>/<your-repo>.git
Clone the repository using Github Desktopβ
Open Github Desktop and click File > Clone repository.
Click URL.
Enter the URL of the repository you want to clone. For example:
https://<your-username>:<your-pat>@github.com/<your-username>/<your-repo>.git
Using SSH Keyβ
Generating new SSH Keyβ
This section is derived from the GitHub Official Documentation, page Generating a new SSH key and adding it to the ssh-agent.
Open Terminal.
Paste the text below, substituting in your GitHub email address.
$ ssh-keygen -t ed25519 -C "your_email@example.com"
noteIf you are using a legacy system that doesn't support the Ed25519 algorithm, use:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This creates a new SSH key, using the provided email as a label.
> Generating public/private ALGORITHM key pair.
When you're prompted to "Enter a file in which to save the key", you can press Enter to accept the default file location. Please note that if you created SSH keys previously, ssh-keygen may ask you to rewrite another key, in which case we recommend creating a custom-named SSH key. To do so, type the default file location and replace id_ssh_keyname with your custom key name.
> Enter a file in which to save the key (/home/YOU/.ssh/ALGORITHM):[Press enter]
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases."
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]
Adding SSH Key to Githubβ
This section is derived from the GitHub Official Documentation, page Adding a new SSH key to your GitHub account.
Copy the SSH public key to your clipboard.
If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.
$ cat ~/.ssh/id_ed25519.pub
# Then select and copy the contents of the id_ed25519.pub file
# displayed in the terminal to your clipboardtipAlternatively, you can locate the hidden
.ssh
folder, open the file in your favorite text editor, and copy it to your clipboard.In the upper-right corner of any page, click your profile photo, then click Settings.
In the "Access" section of the sidebar, click SSH and GPG keys.
Click New SSH key or Add SSH key.
In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal laptop, you might call this key "Personal laptop".
Select the type of key, either authentication or signing. For more information about commit signing, see "About commit signature verification."
Paste your key into the "Key" field.
Click Add SSH key.
If prompted, confirm access to your account on GitHub. For more information, see "Sudo mode."
Testing your SSH connectionβ
This section is derived from the GitHub Official Documentation, page Testing your SSH connection.
Open Terminal.
Enter the following:
$ ssh -T git@github.com
# Attempts to ssh to GitHubYou may see a warning like this:
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?Verify that the fingerprint in the message you see matches GitHub's public key fingerprint. If it does, then type
yes
:> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.
Clone the repository using CLIβ
Go to the repository on GitHub.
Click the Code button.
Click the SSH tab.
Click the clipboard icon to copy the clone URL for the repository.
Open Terminal and navigate to the directory where you want to clone the repository.
Clone the repository using the URL you copied in step 4:
$ git clone git@github.com:<your-username>/<your-repo>.git
Clone the repository using Github Desktopβ
Go to the repository on GitHub.
Click the Code button.
Click the SSH tab.
Click the clipboard icon to copy the clone URL for the repository.
Open Github Desktop and click File > Clone repository.
Click URL.
Enter the URL of the repository you want to clone. For example:
$ git clone git@github.com:<your-username>/<your-repo>.git