Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove git blobs locally

Tags:

git

git clone --filter=blob:none allows me to quickly clone a repo, without having to download gigabytes of objects. The repo size is small, as expected, because git cloned just the latest blobs at that point in time. Say, I work with this repo, switch branches, compare, etc. Git will download objects as and when needed. Now, the size of my repo is again increasing, locally, because of all of the downloaded objects. Is there a way to delete all of the local blobs and retain just the latest blob? In other words, is there a way to reach the same kind of state when I first cloned the repo using the partial clone with all commits, trees, but only the latest blob?

P.S. I know I can clone a fresh partial repo again. But I want to know if something is possible without having to clone again.

like image 375
DannOfThursday Avatar asked Sep 03 '25 06:09

DannOfThursday


1 Answers

This functionality is not directly supported by Git. However, you can use git gc or the more recent (Git 2.30+) git maintenance to decrease the repo size.

git maintenance run --task gc
git maintenance run --task loose-objects --task incremental-repack

This won't be the same as re-cloning the repo, but it should result in a smaller repo.

like image 146
VonC Avatar answered Sep 04 '25 21:09

VonC