Skip to content

Instantly share code, notes, and snippets.

@Hardu2203
Forked from Sanix-Darker/clone_sub.sh
Last active April 10, 2022 23:10
Show Gist options
  • Save Hardu2203/60306dbad152675d29401d318c65aa38 to your computer and use it in GitHub Desktop.
Save Hardu2203/60306dbad152675d29401d318c65aa38 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) !
#!/bin/bash
# First parameter is the sub-directory-absolute-path
# Second parameter is the link of the repo
git clone --filter=blob:none --no-checkout --depth 1 --sparse $2
# A smart split to get the repo-name, with / as a separator
REPO_NAME="$(echo $2 | grep -oE '[^/]+$')"
cd $REPO_NAME
git sparse-checkout init --cone
git sparse-checkout add $1
git checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment