As a developer, in this open-source era, we often try to explore the code base of libraries/frameworks/projects or mostly starter template for kick-starting projects. The most common way is to clone the repository using the git clone
CLI command.
But cloning a repository will download its entire git history with all the branch details which are not needed and it takes time to clone it as well.
So how can we quickly download a GitHub repository?
Well, there are a couple of ways we can do it,
- Download as a zip file via GUI
The easiest way from GUI. The zip file will be downloaded without git version control. We can then unzip and start working on it.
Here we won’t be able to download specific folders.
- git clone —depth 1
With this method, we will be cloning the repository with only the last commit. This will be faster than the clone command without any args. Let’s say if we are cloning a project template we don’t want the template’s git history or certain files like license, etc. It would be inconvenient for us to do re-init git and reset origin remote pointer and mostly we are likely to forget doing those due to the project’s excitement.
- Via degit
degit is a cooler way of cloning a project from a remote repository if you are a keyboard user. It majorly supports Github/GitLab/BitBucket/Sourcehut.
We can globally install or run the commands using npx.
npm install degit -g
To create a new folder for the project.
degit user/repo my-new-project
// eg. npx degit sveltejs/template svelte-app
By default master
branch will be cloned. We can even clone based on a tag, branch, or a commit
npx degit user/repo#dev # branch
npx degit user/repo#v1.2.3 # release tag
npx degit user/repo#1234abcd # commit hash
Here comes the coolest part, we can clone only a specific folder instead of downloading the entire repository 🤩
npx degit user/repo/subdirectory
// eg. npx degit sveltejs/template/src
// This will download only the src folder
It also provides additional features like executing post scripts that helps us to run commands like npm install
Alternative - zel
How this is different from the 2nd solution?
Author’s Rich Harris Reply here
Happy solving!
References
Top comments (0)