In general, you can do this by cloning the repositories to your system with a shell script and then extracting the files from your system. If you'd rather download less data, you can use a partial clone (e.g., git clone --filter=blob:none
) and then only the blobs you need will be pulled down on demand.
If you just need a branch or two from each repository and they're all from GitHub, you can use the GitHub REST API to download a tarball for the branch and repository you need. Note that you'll need to use a personal access token if you make more than 60 requests per hour.
If you have a partial clone, you can also use sparse checkout to filter only the files you want. However, you could also use git archive
to produce a tarball, and if you have a tarball, either from git archive
or GitHub's API, you can extract only certain files or folders like so:
tar -C DESTDIR -xf foo.tar.gz folder1/ folder2/
Do note that the GitHub REST API doesn't provide the ability to download only a subset of data. You have to download a tarball consisting of an entire tree or commit.