DEV Community

Gerry Tan
Gerry Tan

Posted on

Fast clone of large git repo to read code in IDE

How often do you find yourself wanting to clone a repo owned by someone else just to load it in your IDE for quick searching / improved navigation / syntax highlighting / etc.?

This is problematic on a large repo with tons of history because the initial full clone can take an hour or more!

Fear not! Shallow git clone to the rescue. Next time you're in this situation:

  1. git clone --depth=1 <url_of_the_repo>
  2. Load the code in the IDE

You'll notice the clone will be a lot faster!

A shallow clone works fine if all you do is just reading code in IDE. However other functionalities are limited / won't work.

What you should do right after a shallow clone is open a new terminal window, and run:

git fetch --unshallow
Enter fullscreen mode Exit fullscreen mode

Which will fetch all those long history.

Let this run for however long it wants (and make sure you're not on limited mobile data plan 😉).

The bottom line is, using this method you can temporarily bypass the expensive fetching of full history, and get only the latest version for immediate reading 🍻.

And by the way most CI/CD pipeline does a shallow clone too since all they care is the last version of the code.

Top comments (0)