Skip to content

Instantly share code, notes, and snippets.

@MAgungHKM
Last active January 16, 2021 15:27
Show Gist options
  • Save MAgungHKM/85756afc1d14815e4b8ddfa2539b266b to your computer and use it in GitHub Desktop.
Save MAgungHKM/85756afc1d14815e4b8ddfa2539b266b to your computer and use it in GitHub Desktop.
This is a simple Bash function for downloading a specific folder from a GitHub Repository which I created from this [link](https://stackoverflow.com/a/44109535). You can place this inside your bashrc or any other file. As far as testing goes, everything seems to be working fine.
# custom download git folder function/command
git-grab() {
if [ $# -lt 3 ]; then
# Display Help
echo "This function will download specific folder/directory of a github repo"
echo
echo "Syntax: git-grab <user-name> <repo-name> <directory> # download from master branch"
echo "Syntax: git-grab <user-name> <repo-name> <branch> <directory> # download from a specific branch"
echo
elif [ $# -eq 3 ]; then
wget -O - https://github.com/"$1"/"$2"/archive/master.tar.gz | tar -xz --strip=2 "$2-master/$3";
else
wget -O - https://github.com/"$1"/"$2"/archive/"$3".tar.gz | tar -xz --strip=2 "$2-$3/$4";
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment