Clone repositories without the entire history in Git
There comes a time when you want to clone a Git repository through GitHub or a similar client but at the same time, you don’t want the entire history of that repository.
This can help speed up the entire
git clone process for you.
There’s a provision to do just that in Git.
So, for instance, if you only want the last commit from a Git repository, it can be done by specifying the
--depth option followed by the number of recent commits you want in the
git clone command. In our case, this would be
Here’s how the command would look like.
$ git clone [email protected]:amitmerchant1990/notepad.git --depth 1
As you can tell, Git will retrieve the latest commit for this repository and if you
git log under this repository, you’ll only see that particular commit in the list.
Similarly, if you need the recent 5 commits, you’ll specify
--depth 5. For 10 commits, it will be
--depth 10, and so on.
You can take this further by only retrieving the specific branch using the
--single-branch option like so.
$ git clone -b main --single-branch [repo] --depth 1