How to download just a folder within a repo #178419
Replies: 8 comments
-
| Unfortunately, GitHub doesn’t provide native support for downloading just a single folder from a repository. The green “Code → Download ZIP” button always downloads the entire repository. However, there are a few reliable alternative solutions you can use: ✅ Option 1 – Use download-directory.github.io This is a community-built tool created by GitHub users that allows you to download any subfolder via URL. This will generate a ZIP file containing only that directory. 🧰 Option 2 – Use Git Sparse Checkout If you prefer doing this from the command line: This will fetch and extract only the required folder, without downloading the rest of the repository. 📦 Option 3 – Use the GitHub API For automated or scripted pipelines, you can use the GitHub Contents API to retrieve the contents of a folder programmatically: 
 | 
Beta Was this translation helpful? Give feedback.
-
| Best Official Method: Use the full repo ZIP and note the subfolder path in your SBOM comments. Direct Download (Unofficial): Use a service like https://download-directory.github.io/ by pasting the folder's URL, but this is not reliable for long-term SBOM use. For Automated Pipelines: Use git with sparse checkout to clone only the specific subdirectory you need. | 
Beta Was this translation helpful? Give feedback.
-
| Thanks for the quick response and I have already reviewed these. This is not just a solution for us, it could be for anyone who has access to an SBOM and want to know what is in the product. They want to go directly to or download the individual package. 
 Most packages are at the 'top' level and the green button is perfect and that is the type of solution that would be great at the folder level. Thanks for the response. I have looked at this, but not always practical. The SBOM Schema does not allow for this as it just has a single field and is expecting a URL that downloads it directly. Then there are some parent downloads that are huge. Dotnet for example, is a couple of hundred megs I believe when all that is wanted is probably less than 100k of code. Still investigation, but I appreciate both your inputs | 
Beta Was this translation helpful? Give feedback.
-
| yeah, github doesn’t have a built in way to download just one folder. the code THEN download zip button always grabs the whole repo at that tag or commit. | 
Beta Was this translation helpful? Give feedback.
-
| I may have a sort of solution. Just checking the SBOM specification, I have just realised that it states it needs to be a URL. It does not state that the URL needs to be an archive link. We had just believed that it did. That solves part of the issue. The second part is that we do need to process just that section of code. We have tools that automatically will download it if it is an archive link as I have above, but that is too large a set of code. My thought is that we could modify our tools to use one of the open source solutions so that when we do need to process a subset of code, we can combine our tools with the open source solution to get just that 'chunk' of code. Yes it would be nice if Github allowed the download just a section of code, but by checking the SBOM specification, I believe I have a workaround. Now for our tools team to implement it! Fingers Crossed. | 
Beta Was this translation helpful? Give feedback.
-
| You could create a straightforward internal script with the GitHub API just to grab the folder you need. It's pretty user-friendly, so even if someone isn't very technical, they can still run it easily. That way, you get a stable URL for your SBOM and keep everything under control. Hope that helps! | 
Beta Was this translation helpful? Give feedback.
-
| Use an Online Tool Tool: Use a website like DownGit or GitZip (which has a browser extension). How: Go to the folder you want on GitHub in your browser. Copy the URL from your browser's address bar. Paste the URL into the tool's text box and press Enter or click Download. It will process the folder and download it for you as a ZIP file. | 
Beta Was this translation helpful? Give feedback.
-
| 
 GitHub’s “Download ZIP” button downloads the entire repository. There’s no GitHub feature to download just one folder. Third-party tools (like download-directory.github.io) exist, but are not official or reliable for compliance. 
 Use the GitHub permalink to the specific folder. Add the full source archive (ZIP) link for that version. Specify the path of your component inside that archive. Record these three together in your SBOM. 
 Name: Microsoft.NETCore.Compilers Version: 4.1.0 License: MIT Copyright: .NET Foundation Technology: .NET Compiler SDK Download location: Source archive: Path inside archive: 
 Fully traceable and verifiable. Meets SBOM compliance (SPDX, CycloneDX, NTIA). Doesn’t rely on external tools. Anyone can reproduce the source easily. 
 --> In short: Use: permalink + ZIP link + folder path → SBOM-compliant and reliable. | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
As a part of recording what open source information is used in a product we have to provide the following information (See SBOM White House edict )
Many open source packages can come from within a section of a repo. For example:
https://github.com/dotnet/roslyn/tree/v4.1.0/src/NuGet
In this directory there are the following separate Nugets
Microsoft.NETCore.Compilers
Microsoft.Net.Compilers.Toolset
Microsoft.Net.Compilers
There can be many, many packages in a single archive. Particularly, when the archive provides the package code for a number of different technologies.
The download location for the first three is https://github.com/dotnet/roslyn/archive/refs/tags/v4.1.0.zip
But we do not need all of them for an individual package. Just the one. I cannot see a way of choosing a folder in Github as the download location.
I can point to the folder -
What we really could do with is the equivalent of the Green button that gives the link we use for that download.
Is there the equivalent specific to Github.
I know there are open source packages that do this sort of thing such as https://download-directory.github.io/, but we cannot rely on this to always be available and why we would prefer this function directly from Github.
Fingers crossed! N.
Beta Was this translation helpful? Give feedback.
All reactions