Skip to content

Instantly share code, notes, and snippets.

@jeetsukumaran
Last active November 22, 2021 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeetsukumaran/1aa1f8e4cfb6a0684fa1e31e864d5e4f to your computer and use it in GitHub Desktop.
Save jeetsukumaran/1aa1f8e4cfb6a0684fa1e31e864d5e4f to your computer and use it in GitHub Desktop.
#! /bin/bash
set -e -o pipefail
prog_name=$(basename ${0})
if [[ -z "$1" || -z "$2" ]]
then
echo "Usage: ${prog_name} <REPO> <SUBDIR> [<DEST>]"
exit 1
fi
REPO=$1
SUBDIR=$2
[[ -n $3 ]] && DEST=${3} || DEST=$(basename ${REPO} .git)
echo "[${prog_name}] Repository: ${REPO}"
echo "[${prog_name}] Subdirectory: ${SUBDIR}"
echo "[${prog_name}] Destination: ${DEST}"
# Clone without populating working tree
git clone --filter=blob:none --no-checkout --depth 1 ${REPO} ${DEST}
# Enter repo
cd ${DEST}
# *SET* (not `add`) subdirectory to sparse-checkout file
git sparse-checkout set ${SUBDIR}
# Checkout dir
git checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment