Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I git subtree a subdirectory of the remote?

Tags:

git

subtree

There's a remote repository with multiple subdirectories (lib/Android and lib/iOS). Is it possible for me to only subtree in lib/Android?

like image 276
fobbymaster Avatar asked Nov 22 '25 19:11

fobbymaster


1 Answers

Yes you can use sparse checkout, which was added in git 1.7.0 .

e.g:

Init repo

mkdir git-subdir
cd git-subdir
git init

Enable Sparse Checkouts

git config core.sparsecheckout true

Tell Git which directories you want

echo "some/dir/" >> .git/info/sparse-checkout

Add the remote

git remote add -f origin https://github.com/git/git.git

Pull

git pull origin master
like image 181
atupal Avatar answered Nov 25 '25 09:11

atupal