As the link in Rogier van het Schip's answer (https://stackoverflow.com/a/41162452/30412497) is broken, but I do not currently have enough reputation to comment, here is the content being linked to in the original answer.
https://jasonkarns.wordpress.com/2011/11/15/subdirectory-checkouts-with-git-sparse-checkout/