Skip to content

Clone a Git Repository

This guide explains how to clone an existing Git repository from GitHub to your local workstation.


Prerequisites

  • Git installed on your system.
  • Access to the GitHub repository you want to clone.
  • (Optional) SSH key configured for GitHub if you prefer SSH authentication.

Steps

  1. Open Terminal
    Navigate to the directory where you want to clone the repository:

    cd path/to/your/projects
    

  2. Get the Repository URL

    • Go to the GitHub page for the repository.
    • Click the Code button and copy the URL (choose HTTPS or SSH).
  3. Clone the Repository

    • Using HTTPS:

      git clone https://github.com/<username>/<repository>.git
      
      You will be prompted for your GitHub username and password (or personal access token).

    • Using SSH:

      git clone git@github.com:<username>/<repository>.git
      
      SSH authentication uses your configured SSH key pair.

  4. Result
    Git will download the repository and create a local copy in the specified directory. The process duration depends on the repository size and your internet connection.

Notes

  • Replace <username> and <repository> with the actual GitHub username and repository name.
  • For SSH, ensure your public key is added to your GitHub account (GitHub SSH setup guide).
  • After cloning, you can navigate into the project folder and start working:
    cd <repository>
    

Troubleshooting

  • If you encounter authentication errors, verify your credentials or SSH key setup.