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

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

  5. Clone the Repository

  6. Using HTTPS:

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

  7. Using SSH:

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

  8. 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.
  • For private repositories, ensure you