Last active
May 22, 2016 10:18
-
-
Save max6cn/5b0ba6be3da182def02671c424d04c18 to your computer and use it in GitHub Desktop.
A cli tool to copy github sub folder, usage: gitcp url
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 -f | |
# full_url=$1 | |
# echo $full_url | |
# t="https://github.com/facebook/stetho/tree/master/stetho-sample" | |
IFS='/' read -ra url <<< $1 | |
full_url=($url) | |
repo_name=${full_url[3]} | |
repo_base=${full_url[2]}"/"${full_url[3]} | |
branch=${full_url[5]} | |
sub_dir=${full_url[@]:6:$((6+${#full_url[@]}))} | |
# echo ${#full_url[@]} | |
# echo $repo_base | |
# echo $repo_name | |
# echo $branch | |
# echo $sub_dir | |
#exit 0 | |
git init ${repo_name} | |
cd ${repo_name} | |
git remote add origin "https://github.com/"${repo_base} | |
git config core.sparsecheckout true | |
"${sub_dir}/*" >> .git/info/sparse-checkout | |
git pull --depth=1 origin $branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment