Last active
May 4, 2022 23:06
-
-
Save AndrianBdn/ae8cedaec5a5df30fdbf to your computer and use it in GitHub Desktop.
git-sparse-clone.sh
This file contains 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/sh | |
# | |
# This script can clone/checkout a single folder from git repository | |
# - Might be used for checking out micro-services from monolithic git repository | |
# | |
# - You can even do checkout into home directory, for example | |
# git-sparse-clone.sh [email protected]:readdle/fluix-web.git /home/login login | |
# | |
# This will cause the shell to exit immediately if a simple command exits with a nonzero exit value. | |
set -e | |
[ $# -ne 3 ] && { echo "Usage: $0 <repository-URL> <repository-path> <local-repo-root-directory>"; exit 1; } | |
repo_url=$1 | |
repo_path=$2 | |
local_repo_root=$3 | |
git clone $repo_url $local_repo_root | |
cd $local_repo_root | |
git config core.sparsecheckout true | |
echo "/$repo_path/**" > .git/info/sparse-checkout | |
git read-tree -m -u HEAD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment