TL;DR – The goal is to have large Git repo cloned with complete history very quickly. This post explains how you can take advantage of your peer’s setup which was done already. So, technically instead of cloning, we are copy pasting your neighbour’s codebase but intelligently.

In this post, I would like to show you an interesting hack to clone and setup codebase which is quite large in size. This is possible once we understand how Git works.

In big organizations, the codebase repositories tend to be very large going up of 15 GB. It could go even way higher in companies like Google, where billions of lines stored in a single repo. Cloning this kind of repo is a nightmare due to network connection hang up, laptop gets into sleep mode etc. You can use attributes like depth to clone at shallow level, to make it better but still it might take a long time, and probably your local repo may not ever contain the complete history ever.

With this hack, you can clone and setup Git repositories of huge sizes without any worry.

When we look at any Git repository, we have 2 things

1. “.git” sub-folder

2. other sub-folders and files

The folder .git is actually the source of truth of the current state of your repository folders/files, but it will be in a crypted format. Whenever you try to checkout any commit, your workspace folders/files will be forced to reflect that commit state.

This essentially means, we have 2 copies of codebase. One in crypted format, other in normal file/folders format. So, this thought struck to me, can we just copy the .git folder somewhere else and regenerate the entire repo. That led to this finding.

So the conclusive steps are like this:

Find somebody who has the repo setup done. Copy the .git folder (you can do zipping and copy to flash drive and host it some S3 or network drive, download via download managers etc.) Paste the .git into the target folder, and run these commands

$ git status # Here it will show a lot of files got deleted from the repository $ git checkout -- . # This one is for un-doing all the changes (files deletion - previous command info) in one shot. # Consequence of this is, your whole directory of files/sub-folders get regenerated with in a very very short time.

That’s all. Now you have a working codebase directory clone setup done. The caveat is that sourcing is done by a person who has the repo setup already done or by someone who can afford good internet connection. Hope you like this trick and take advantage of this. Please let me know if you have any doubt and I will be very happy to receive any feedback. Thanks.