Solution to Step 0 - START
Solution to Step 1 - Perform sparse clone
Create a sparse clone of repo named myrepo, verify that only top-level files have been fetched into the workspace.
$ git clone --sparse repo myrepo
Cloning into 'myrepo'...
done.
$ cd myrepo
myrepo $ ll
total 4.0K
-rw-r--r-- 1 vscode vscode 181 README.md
myrepo $ cd ..
Solution to Step 2 - Add directory
Add the directory component-a. Check the new configuration. Validate that component-a is now present.
$ cd myrepo
myrepo $ git sparse-checkout add component-a
myrepo $ git sparse-checkout list
component-a
myrepo $ git checkout
Your branch is up to date with 'origin/main'.
myrepo $ ll
total 8.0K
drwxr-xr-x 2 vscode vscode 4.0K component-a
-rw-r--r-- 1 vscode vscode 181 README.md
myrepo $ cd ..
Solution to Step 3 - Disable sparse checkout
| Disable sparse-checkout and perform a checkout again. |
| Validate that all files are now present. |
$ cd myrepo
myrepo $ git sparse-checkout disable
myrepo $ git checkout
Your branch is up to date with 'origin/main'.
myrepo $ ll
total 12K
drwxr-xr-x 2 vscode vscode 4.0K component-a
drwxr-xr-x 2 vscode vscode 4.0K component-b
-rw-r--r-- 1 vscode vscode 181 README.md
myrepo $ cd ..
Solution to Step 4 - Clone and checkout
Clone myrepo, restrict to component-a and do a checkout. Use the --cone option.
$ git clone --sparse repo myclone
Cloning into 'myclone'...
done.
$ cd myclone
myclone $ git sparse-checkout init --cone
myclone $ git sparse-checkout add component-a
myclone $ git checkout
Your branch is up to date with 'origin/main'.
myclone $ ll
total 8.0K
drwxr-xr-x 2 vscode vscode 4.0K component-a
-rw-r--r-- 1 vscode vscode 181 README.md
myclone $ cd ..