Have you felt particularly annoyed by the time it takes to clone a large repository, especially one with a huge commit history? This post will discuss a simple but powerful technique to significantly improve git clone performance.
The solution is called shallow cloning, which uses the --depth=1
flag with git clone
. The reason why this improves git clone performance is that it creates a clone of the git repository with history up to the depth field that we specify. So, in this case, only the most recent commit (and some necessary metadata) is fetched, and nothing else. This helps skip any older commits, tags, branches, etc. Skipping everything else helps reduce the download size and the time it takes. This is particularly useful to improve git clone performance on a CI server. All we need to do is use
git clone --depth=1 <repository-url>
JavaScriptIt is worth mentioning that while shallow cloning does improve the clone performance, it probably is not useful if you want access to the full commit history. It also means there is no branch history, so switching to a different branch would require additional fetches. So shallow cloning is ideal for continuous integration/deployment pipelines, automated build systems, and cases where you want a quick setup for testing or performing code reviews.
If you are looking for other git-related hacks, do check out our posts about removing file from git history and deleting git branches that do not exist on remote.
I am terrible at optimizing my keyboard layout for anything. But off lately, my little…
I recently switched completely to the Brave browser and have set ad blocking to aggressive…
I was preparing a slide deck for a hackathon and decided to put in a…
I have been using npx a lot lately, especially whenever I want to use a…
Manually copy-pasting the output of a terminal command with a mouse/trackpad feels tedious. It is…
While working on a project, I wanted to do an integrity check of a file…