DEV Community

Mohan Sandesh
Mohan Sandesh

Posted on

Faster Git Clone Using depth Option

When cloning open-source repositories from GitHub, especially popular ones, it can take a minute. This delay happens because Git fetches all commits in the main branch from the beginning.

Shallow Clone

A shallow clone is essentially cloning only the latest snapshot of the repository. You can do this by passing --depth option as below.

git clone --depth 1 <repository_url>
Enter fullscreen mode Exit fullscreen mode

This is helpful when you need only the latest commit and don't need the full commit history. It’s particularly beneficial when working with large repositories.

After performing a shallow clone using depth, you can run git log to see the number of commits it fetched.

You can read more about git depth in Git Documentation.

Top comments (0)