What Is Meant by Shallow Cloning a Git Repository?

In Git, shallow clone means cloning only a limited portion of the commit history of a repository as opposed to cloning the entire history of the repository (including all past commits and branches). For example, the following will fetch only the two most recent commits (as specified by the depth parameter) from the repository's history:

$ git clone --depth=2 <remote-url>

This will result in only the latest commit and its immediate parent commit being cloned from the specified repository.

Shallow cloning a repository can be particularly useful when working with large repositories that have extensive histories as it saves you time and disk space by fetching only the most recent commits and avoiding the download of the entire commit history.

However, it's important to note that shallow cloning has limitations. Since only a limited number of commits are fetched, some git operations that require access to the full commit history may not work until you convert the shallow clone to a fully cloned repository.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.