Git is the most popular version control system used by almost all the software projects. However, it is not the only version control software, there are other popular tools like Subversion and Fossil. You can use Subversion on GitHub for managing your source code.
Why would you partially clone a project?
While cloning the entire repository is generally easier, it a a few drawbacks - it takes longer, uses more bandwidth and takes extra space on your hard drive. These issues are exacerbated if you only want a small portion of a humongous repository.
If you want to download files which have been overwritten then you would need to clone the repository and then revert changes, this takes time and requires knowing how to run necessary git commands.
Although you can download single files easily from
raw.github.com, downloading multiple files or entire sub-directories is not possible via this method.
How to clone a sub-directory?
There are multiple ways of downloading sub directories, in this article we will explore two methods to achieve this:
Using the Web interface
There is a excellent tool called download-directory, it can download files and folders from any GitHub repository. You can even download files from different branches and older commits which might have been overwritten. You just need to pass the GitHub URL of the repository and it will be zipped and downloaded for you. it does not work with GitLab
Using the terminal
When working with servers, I often encounter situations where I need to run a tool that requires a desktop environment. We can use the CLI method for such instances. This method is can also be used to make automated shell scrips.
Step 1: Construct the URL to download
In the URL, replace
trunk if you want to clone the latest version from master branch.
branches if you want to clone a particular banch.
# GitHub URL https://github.com/TheAlgorithms/Python/tree/Write-for-current-Python/knapsack # URL for SVN https://github.com/TheAlgorithms/Python/branches/Write-for-current-Python/knapsack
Step 2: Verify the files before downloading
You can list the files you are about to download by running
svn list <url> in your terminal.
Step 3: Download the files
You can download the files using
svn export <url> <local_folder>. This creates a directory locally with the content of the specified subdirectory of the project.
We can use download-directory and
svn command to download sub directories of a git project from GitHub. This is useful if you only want to clone a small portion of a particular repository.
I have not yet been able to successfully download a particular commit via CLI method or download files from other git hosting providers like GitLab. If you know a way to do so, feel free to share your knowledge in the comments.