GitHub download partial repository

There may be times when a developer wants one or two projects from a GitHub repository rather than downloading the entire repository.

Prerequisite

  1. Git needs to be installed which can be download here.
  2. Double click on the file once downloaded.
  3. Under options select Windows Explorer integration.
  4. Follow through with the remaining options/prompts e.g. select an editor etc.
Downloading one or more projects
Select a GitHub repository url and the folders to download.

For example, the repository

There are two projects, Events_1 and ExceptionHandling (which Events_1 project references).

Create a folder on the computer, create a batch file with the following commands.

mkdir code
cd code
git init
git remote add -f origin https://github.com/karenpayneoregon/code-samples-csharp
git sparse-checkout init --cone 
git sparse-checkout add Events_1
git sparse-checkout add ExceptionHandling
git pull origin master

Run the batch file, copy the folders to a Visual Studio solution and if needed do a Restore NuGet Package command inside of Visual Studio by right clicking on the solution explorer.

Caveats
  • There will be root files besides the folder but no worries all that is needed are the folders and the entire code folder is a temp folder.
  • Older versions of Git may not work. At the command line or powershell command line type the following to get Git version. git --version The version should be 2.28.0 or better, may work with one version down.






Comments

Popular posts from this blog

VB.NET Working with Delegate and Events

Coders asking questions in online forums