Partial clone in Git

If you want to clone only a part of history in Git, use --depth option to create a shallow clone with only specified number of commits :

# Create a shallow clone.
$ git clone --depth <depth> <repository-url>

# Examples:
# Clone only 1 commit
$ git clone --depth 1 https://github.com/libgit2/libgit2

You can also create a shallow clone by specifying a date :

# Create a shallow clone with history after 2018-05-01
$ git clone --shallow-since=2018-05-01 https://github.com/libgit2/libgit2

And more, -shallow-exclude=<revision> allows you to create a shallow clone with history after a commit.

Leave a Reply