Clone a Specific Subfolder from a GitHub Project

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2547
Joined: Fri Aug 13, 2004 5:10 pm

Clone a Specific Subfolder from a GitHub Project

Post by jussij »

Step 1: Clone the git repo to the <repo folder>

Code: Select all

git clone --depth 1 --filter=blob:none --sparse <repo>
Step 2: Go to the folder created by the clone and checkout the <subfolder>

Code: Select all

cd <repo folder>
git sparse-checkout set <subfolder>
NOTE: You only have to provide the last name of that sub-folder.

For example consider this repo:

Code: Select all

https://github.com/dotnet/samples
It contains this subfolder:

Code: Select all

https://github.com/dotnet/samples/tree/main/core/interop/cpp-cli
To checkout that sub-folder perform these two steps.
Step 1

Code: Select all

git clone --depth 1 --filter=blob:none --sparse https://github.com/dotnet/samples
Step 2

Code: Select all

cd samples
git sparse-checkout set cpp-cli
NOTE: Notice how only the last name in that subfolder is required which in this case was: cpp-cli

This will check out that subfolder:

Code: Select all

Volume in drive D has no label.
 Volume Serial Number is 7410-AB8C

 Directory of D:\Projects\samples\core\interop\cpp-cli

22/09/2022  09:41 AM    <DIR>          .
22/09/2022  09:41 AM    <DIR>          ..
22/09/2022  09:41 AM             3,853 CPP-CLI.sln
22/09/2022  09:41 AM               205 Directory.Build.props
22/09/2022  09:41 AM    <DIR>          ManagedApp
22/09/2022  09:41 AM    <DIR>          ManagedLibrary
22/09/2022  09:41 AM    <DIR>          MixedLibrary
22/09/2022  09:41 AM    <DIR>          NativeApp
22/09/2022  09:41 AM             2,684 README.md
22/09/2022  09:41 AM                34 snippets.5000.json
               4 File(s)          6,776 bytes
Cheers Jussi
Post Reply