Data report"State of code review 2024" is now liveRead the full report

Troubleshooting `git clone`

Greg Foster
Greg Foster
Graphite software engineer


Note

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


When attempting to clone a Git repository, you might encounter a variety of issues that prevent the clone process from executing successfully.These problems can range from network issues to authentication errors.

This guide will walk you through common git clone errors, their causes, and how to resolve them, ensuring you can successfully clone your desired repository.

Message:

Terminal
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

Cause: This error typically occurs when trying to clone a repository over SSH without having an SSH key added to your GitHub (or other service) account, or when the key is not correctly configured on your machine.

Fix:

  1. Generate an SSH Key (if you haven't already):

    Terminal
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    Follow the prompts to generate your SSH key.

  2. Add the SSH Key to Your SSH Agent:

    Terminal
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_rsa
  3. Add the SSH Key to Your GitHub Account:

    • Copy your SSH public key to your clipboard:
      Terminal
      cat ~/.ssh/id_rsa.pub | clip
    • Go to the New SSH key settings page in GitHub, and paste your key.

    Follow the official documentation on adding SSH keys if you get stuck.

  4. Retry cloning:

    Terminal
    git clone git@github.com:username/repository.git

Message:

Terminal
fatal: repository 'https://github.com/username/repository.git/' not found

Cause: This error occurs if the repository URL is incorrect, the repository does not exist, or you do not have permission to access it.

Fix:

  • Check the repository URL: Ensure you've entered the correct URL for cloning.
  • Repository visibility: If the repository is private, ensure you have access to it. For GitHub, you might need to authenticate or use SSH cloning.

Message:

Terminal
fatal: unable to access 'https://github.com/username/repository.git/': Could not resolve host: github.com

Cause: This is typically a network or DNS issue, where your computer can't resolve the domain name into an IP address.

Fix:

  1. Check your internet connection: Ensure you're connected to the internet.
  2. Flush Your DNS Cache:
    • On Windows:
      Terminal
      ipconfig /flushdns
    • On macOS and Linux:
      Terminal
      sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Message:

Terminal
fatal: unable to access 'https://github.com/username/repository.git/': SSL certificate problem: unable to get local issuer certificate

Cause: Git can't verify the SSL certificate provided by the remote repository, possibly due to a missing CA bundle on your system. This typically only happens when using a Linux distribution.

Fix:

  1. Update CA certificates:
    • On Debian/Ubuntu:
      Terminal
      sudo apt-get update && sudo apt-get install ca-certificates
    • On Fedora/CentOS:
      Terminal
      sudo yum update && sudo yum install ca-certificates
  2. Temporarily disable SSL verification (not recommended for security reasons):
    Terminal
    git -c http.sslVerify=false clone https://github.com/username/repository.git
  • Check Git's configuration: Use git config --list to review your Git settings. Misconfigurations, especially with http.proxy or https.proxy, can cause issues.
  • Update Git: Ensure you're using the latest version of Git. Older versions might lack certain bug fixes or features.
  • Use HTTPS Instead of SSH (and vice versa): If one protocol doesn't work, try the other. HTTPS might be more firewall-friendly, for example.

Cloning issues in Git can stem from a variety of sources, including network problems, configuration errors, and permissions issues. By systematically checking the most common causes and applying the fixes outlined above, you can resolve most git clone errors and successfully clone the repository you need.

Always ensure your Git environment is correctly set up and that you have the necessary access rights to the repository you're attempting to clone.

For more information on git clone see the official documentation.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Learn more

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2