Last active
June 6, 2021 07:33
-
-
Save souvikinator/0dbda7832a63af6a1cabd09b585d73cd to your computer and use it in GitHub Desktop.
Downloading a specific directory from Github
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/bash | |
#usage: | |
#arg1: directory where you want to save the specific sub dir from repo | |
#arg2: the repo clone url | |
#arg3: name of the specific directory | |
#ex: ./getGitDir.sh <outputdir> <cloneurl> <targetdir> | |
#get no of args passed | |
TOTALARGS="$#" | |
if [[ $TOTALARGS -lt 3 ]]; then | |
echo "$# arguments specified, required 3 :(" | |
echo "arg1: outdir, arg2: git repo url, arg3: target directory" | |
exit 1 | |
fi | |
#dir to save template, git url of repo, template name | |
DIR="$1" | |
GITURL="$2" | |
TARGETDIR=$"$3" | |
#check whether directory exits | |
if [[ ! -d "$DIR" ]]; then | |
#make dir | |
mkdir "$DIR" | |
#get inside the folder | |
cd $DIR | |
#git init | |
git init | |
#set origin | |
git remote add -f origin $GITURL | |
fi | |
#get inside the folder | |
cd $DIR | |
#perform sparse checkout | |
git config core.sparsecheckout true | |
echo "$TARGETDIR" >> .git/info/sparse-checkout | |
git checkout master | |
git pull origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment