Search code examples
gitgit-lfs

Git: reduce the size of `.git/lfs/`


I use git-lfs to track large files, the setup is:

.
├── ...
├── ...
├── large-files
├── ...
├── ...
└── .git

where an external storage is mounted on large-files, and all large files go here.

The problem with this setup is, there is a .git/lfs directory, which uses the same amount disk spaces as the large-files, since I will never delete from large-files, and my SSD, where the working tree resides, has smaller capacity than the external storage, .git/lfs will outgrow my SSD's capacity.

Is there a way to reduce the size of this .git/lfs without moving it to an external storage? (putting .git or the entire working tree to the external storage is not an option, because the external storage is not always available)


Solution

  • .git/lfs is the local cache directory for git-lfs, Git Large File Storage. It keeps the repository size down by storing the history of large files in cloud storage instead of in local history.

    .git/lfs will not grow indefinitely. It's normal for git-lfs to cache "recent" versions of large files there. You can run git lfs prune to have it prune the cache, and you can configure how much it prunes with lfs.pruneoffsetdays and lfs.fetchrecent.

    You can also put this directory elsewhere by changing lfs.storage.