Last active
November 22, 2021 01:41
-
-
Save jeetsukumaran/1aa1f8e4cfb6a0684fa1e31e864d5e4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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