I recently wanted to download a sample SignalR app from the Microsoft docs, and in the docs, Microsoft had bundled all of their sample applications into the same GitHub repository.

I only wanted a single folder:


The suggestion was to download the entire repository. I thought there must be a better way for me – and my hard drive – so I dug into Git a little and found this excellent technique.


A feature added in 2016 called sparse checkout allows you to specify folders you want to exclude and include in a git checkout. So to just download the signalr/sample folder here is the command.

git clone --no-checkout --depth 1 --single-branch https://github.com/aspnet/Docs.gitcd docsgit config core.sparsecheckout trueecho "aspnetcore/tutorials/signalr/sample/*" >> .git/info/sparse-checkoutgit checkout master

You will notice that if you run the above, the clone command on line 1 still downloads a number of objects. This is the git history. I couldn’t find a way to avoid this. However it is still far quicker than downloading the whole repository.

If you find a better way. Let me know.