Skip to content

Instantly share code, notes, and snippets.

@Sanix-Darker
Created June 17, 2021 09:50
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Sanix-Darker/a15f3d9a0eed10236ff25c87b5515732 to your computer and use it in GitHub Desktop.
Save Sanix-Darker/a15f3d9a0eed10236ff25c87b5515732 to your computer and use it in GitHub Desktop.
[BASH]clone_sub.sh
#!/bin/bash
# First parameter is the sub-directory-absolute-path
# Second parameter is the link of the repo
# A smart split to get the repo-name, with / as a separator
REPO_NAME="$(echo $2 | grep -oE '[^/]+$')"
git init $REPO_NAME
cd $REPO_NAME
git remote add origin $2
git config core.sparsecheckout true
# Specipy the sub directory
echo "$1/*" >> .git/info/sparse-checkout
# then get it, the depth is the way too far wher you can go...
git pull origin master
# and badaboum, you only get your sub-dir
# this script is functionnal for github/gitlab and bitbucket
# Have FUN (darker) !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment