DannOfThursday
DannOfThursday

Reputation: 83

Remove git blobs locally

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.

Upvotes: 4

Views: 367

Answers (1)

VonC
VonC

Reputation: 1326782

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.

Upvotes: 2

Related Questions