Skip to main content

Shallow Repository Cloning

Overview

Shallow cloning of a git repository can offer some performance improvement, especially for larger projects with a number of commits, by pulling the smallest number of changes possible. This can be implemented manually using a custom cloning step.

Configuring your shallow checkout

To fetch and modify the default checkout step, see this article: How do I modify the checkout step?

Some flags to note that can be added to the git clone <repository> command:

  • --depth <depth> will limit the number of commits fetched for the repository or branch being checked out.

  • --shallow-since=<date> will do a shallow checkout from the date specified (date should be formatted as YYYY-MM-DD)

  • --no-tags prevents git from cloning any tags from the repository (if the installed version of git supports it).

Here is an example:

version: 2.1jobs:
  build:
    docker:
      - image: cimg/node:latest
    steps:
      - run: git clone --depth 5 "$CIRCLE_REPOSITORY_URL" --branch "$CIRCLE_BRANCH"

You can read more information on Git's website:

Support for Shallow Checkouts on Windows

Shallow checkout and git clone commands with a --depth parameter are not guaranteed to work in Windows Execution environments on CircleCI.

There is an open feature request which can be found at the link below:

There are a few workarounds that can be used here:

Additional Resources

Did this answer your question?