Can you convert an existing git repository to be a "blobless" one?

Viewed 270

Today, git offers "partial clone" options that enable downloading the commits and trees of a repository, while allowing blobs to be downloaded on-demand, saving network bandwidth and disk space.

This can be enabled during the initial git clone by passing --filter=blob:none. However, is there a way to convert an already existing local repository to the "blobless" format? This should save some disk space by deleting any local blobs known to be available from the "promisor" remote.

1 Answers

While I'm not aware of a dedicated in-place command, you can still perform a local cloning and then replace your original folder with the blobless copy.
(solution inspired by knittl comment)

# If it's your first time, you'd need to enable filtering locally.
git config --global uploadpack.allowFilter true

# Filter your existing repo into a new one.
# The `file://` protocol followed by a full path is required.
git clone --filter=blob:none file:///full_path_to_existing_repo/.git path_to_new_blobless_copy

# Reconfigure the origin of your new repo.
# You can retrieve it with `git remote -v` in your existing repo.
cd path_to_new_blobless_copy
git remote set-url origin remote_path_to_origin.git
cd -

# Replace your existing repo with the new one.
# Destructive operation that will free up the space of the blobs.
# But will also destroy your local stashes, branches and tags that you didn't clone!
rm -rf /full_path_to_existing_repo
mv path_to_new_blobless_copy /full_path_to_existing_repo
Related