Today I Learned

2022/03/06

git shell

About git-sparse-checkout:

The general script for doing a sparse checkout is:

#!/usr/bin/env bash
git_url="${git_url:?required}"
target_dir="${target_dir:?required}"

is_git_dir() { git rev-parse; }

init() {
  mkdir -p "$target_dir" && cd "$target_dir"
  if ! is_git_dir; then
    git init && git remote add -f origin "$git_url"
  fi

  git config core.sparseCheckout true &&
    git sparse-checkout init &&
    git sparse-checkout set test &&
    git pull origin master
}

see also: https://about.gitlab.com/blog/2020/03/13/partial-clone-for-massive-repositories/