Skip to content

Instantly share code, notes, and snippets.

@winterrdog
Forked from Sanix-Darker/clone_sub.sh
Last active January 10, 2022 10:10
Show Gist options
  • Save winterrdog/11a55439d9a1a14df036887c26f6b3d2 to your computer and use it in GitHub Desktop.
Save winterrdog/11a55439d9a1a14df036887c26f6b3d2 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
# Specify the sub directory
echo "$1/*" >> .git/info/sparse-checkout
# then get it, the depth is the way too far where 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