Perform Shallow Clone of Git Repository

Perform Shallow Clone of Git Repository

Cloning a Git repository can sometimes be slow, especially when dealing with large repositories with long commit histories. If you only need the latest version of the code without the entire commit history, you can use a shallow clone to accelerate the process and save disk space. This tutorial explains how to perform a shallow clone of Git repository.

A shallow clone is a Git clone operation that limits the depth of history retrieved. This is useful for when only need to compile the source code or in the continuous integration/continuous delivery (CI/CD) pipelines.

1. Default branch

The simplest way to perform a shallow clone is by specifying the --depth=1 option. This tells Git to fetch only the latest commit, reducing the amount of data downloaded. Example:

git clone https://github.com/opencv/opencv.git --depth=1

The command clones the default branch.

2. Specific branch

To clone a specific branch instead of the default branch, you can specify the --branch option along with --depth=1. Example:

git clone https://github.com/opencv/opencv.git --depth=1 --branch=next

3. Specific tag

Sometimes, you might need a specific version of a repository, such as a release tag. You can do this by specifying the tag name with --branch. Example:

git clone https://github.com/opencv/opencv.git --depth=1 --branch=4.11.0

Leave a Comment

Cancel reply

Your email address will not be published.