How to clone a subdirectory of a git project (not downloading the zip).
source link: https://dev.to/sanixdarker/git-cloning-a-subdirectory-of-a-gi-project-2mld
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to clone a subdirectory of a git project (not downloading the zip).
Aug 21
・1 min read
Have you ever wonder a way to clone a specific folder in a git repository ?
hop hop hop, easy.. he was not talking about Downloading a ZIP(like DownGit does), but only cloning a sub-dir, just to make things clear !
I got that question from a friend, and i wrote a small and interesting bash script to do so :
#!/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
Source Code : Gist-Code
Have FUN !
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK