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

Troubleshooting when git clone is slow or hanging

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

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


When you run into issues with a git clone command that's slower than expected, it can be a frustrating experience, especially if you're trying to get started on a project quickly. Several factors can contribute to this problem, ranging from network issues to large repository sizes. Here's how to troubleshoot and potentially speed up your git clone command.

The first step is to ensure that your internet connection is stable and fast enough for Git operations. Git cloning, especially of large repositories, can be significantly affected by your network speed.

  • Test your internet speed: Use online tools like Speedtest by Ookla to check your download speed.
  • Check your network settings: Ensure that your firewall or proxy settings are not interfering with Git. Sometimes, corporate networks have restrictions that might slow down Git operations.

If you don't need the entire history of the repository, you can perform a shallow clone. This clones the repository with a limited number of commits from the history, thus reducing the amount of data transferred.

Terminal
git clone --depth 1 <repository-url>
  • --depth 1 tells Git to pull only the latest commit for each branch, significantly reducing clone time.

If you only need to work with a specific branch, specify it in your clone command to avoid downloading all branches.

Terminal
git clone --single-branch --branch <branch-name> <repository-url>
  • --single-branch limits the clone to a single branch.
  • --branch <branch-name> specifies which branch to clone.

Sometimes the physical distance or the network route between your location and the Git server can affect the clone speed. If the repository you are cloning is hosted on multiple servers around the world, try to clone from a server that is geographically closer to you.

Repositories with large files can take a long time to clone. If you manage the repository:

  • Use Git LFS: Move large files to Git Large File Storage (LFS) to avoid cloning them directly.
  • Clean up the repository: Remove unnecessary large files or old branches that are no longer needed.

Make sure you are using the latest version of Git, as performance improvements and bug fixes are regularly added.

Terminal
git --version
sudo apt update && sudo apt upgrade git

To see what Git is doing during the clone process, you can use the verbose option:

Terminal
git clone --verbose <repository-url>

This will give you more detailed output, which can help in diagnosing where the slowdowns are occurring.

By following these steps, you should be able to diagnose and possibly fix a slow git clone command. Remember, the specific solution may vary depending on the exact nature of the problem, whether it's network-related, due to large repository size, or configuration issues.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2