Skip to content

Instantly share code, notes, and snippets.

@nobk
Last active January 8, 2022 19:41
Show Gist options
  • Save nobk/5ee4ed663aa5f915d251675510c0b3d9 to your computer and use it in GitHub Desktop.
Save nobk/5ee4ed663aa5f915d251675510c0b3d9 to your computer and use it in GitHub Desktop.
git partial clone filtering directories
REPONAME="knew"
OLDFULLREPO="k8"
git init $REPONAME
cd $OLDFULLREPO
ls -1 > ../${REPONAME}/.git/info/sparse-checkout
GITURL="$(git remote show origin | awk '/Fetch URL/ {print $3}')"
cd ../$REPONAME
nano .git/info/sparse-checkout # remove unwanted dirs
git config --local core.sparsecheckout true
git remote add origin "$GITURL"
git pull origin master
git branch --set-upstream-to=origin/master master
git pull
ls -1 | diff .git/info/sparse-checkout -
cd ../${OLDFULLREPO}
ls -1 | diff ../${REPONAME}/.git/info/sparse-checkout -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment