How to clone only one subdirectory from Git repository?

3.2k Views Asked by At

I have following repository:

= dir 1
 -- subdir1
 -- subdir2

= dir 2

And I want to clone e.g. dir2 and dir1/subdir1. I followed instructions from this question: How do I clone a subdirectory only of a Git repository? and I've made this:

mkdir ${projectName} &&
cd ${projectName} &&
git init &&
git remote add -f origin <url> &&
git config core.sparseCheckout true &&
echo "dir2" >> .git/info/sparse-checkout &&
git config core.sparseCheckout false &&
echo "dir1/subdir1" >> .git/info/sparse-checkout &&
git pull origin main &&
git config core.sparseCheckout false

where appChoice is subdir1. After executing this command, I've get dir1 with both subdirectories: subdir1 and subdir2. Where is the mistake?

0

There are 0 best solutions below