Clone a Specific Subfolder from a GitHub Project
Posted: Tue Jul 12, 2022 2:18 am
Checkout Process
Step 1 - Clone Repo
Clone the git repo using the <base url> as follows:
Step 2 Checkout Subfolder
Go to the <repo folder> created by the clone and checkout the <subfolder> as follows:
Typical Example
As an example consider a repo with these base url:
It contains the following subfolder:
That means these are the values needed for the commands:
NOTE: The <repo folder> is the name of the folder created by clone and should be the last element of the repo base URL.
NOTE: The <subfolder> is just the name of the folder which is represented by the last element of the subfolder URL.
Using those details the two steps for the checkout are as follows:
Step 1 - Clone Repo
Step 2 Checkout Subfolder
These steps will check out that subfolder:
Cheers Jussi
Step 1 - Clone Repo
Clone the git repo using the <base url> as follows:
Code: Select all
git clone --depth 1 --filter=blob:none --sparse <base url>
Go to the <repo folder> created by the clone and checkout the <subfolder> as follows:
Code: Select all
cd <repo folder>
git sparse-checkout set <subfolder>
As an example consider a repo with these base url:
Code: Select all
https://github.com/dotnet/samples
Code: Select all
https://github.com/dotnet/samples/tree/main/core/interop/cpp-cli
Code: Select all
<base url> => https://github.com/dotnet/samples
<repo folder> => samples
<subfolder> => cpp-cli
NOTE: The <subfolder> is just the name of the folder which is represented by the last element of the subfolder URL.
Using those details the two steps for the checkout are as follows:
Step 1 - Clone Repo
Code: Select all
git clone --depth 1 --filter=blob:none --sparse https://github.com/dotnet/samples
Code: Select all
cd samples
git sparse-checkout set cpp-cli
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