You can use the below command
git lfs prune
From docs,
DESCRIPTION
Deletes local copies of LFS files which are old, thus
freeing up disk space. Prune operates by enumerating all the locally
stored objects, and then deleting any which are not referenced by at
least ONE of the following:
- the current checkout
- a 'recent branch'; see [RECENT FILES]
- a 'recent commit' on the current branch or recent branches; see [RECENT FILES]
- a commit which has not been pushed; see [UNPUSHED LFS FILES]
- any other worktree checkouts; see git-worktree(1)
In general terms, prune will
delete files you're not currently using and which are not 'recent', so
long as they've been pushed i.e. the local copy is not the only one.
The reflog is not considered, only commits. Therefore LFS objects that
are only referenced by orphaned commits are always deleted.
Note: you should not run git lfs prune if you have different
repositories sharing the same custom storage directory; see
git-lfs-config(1) for more details about lfs.storage option.
Since you are unable to prune due to the LFS tracked files being referenced by the current checkout, you can clone the local repo without the LFS tracked files using the GIT_LFS_SKIP_SMUDGE
setting
export GIT_LFS_SKIP_SMUDGE=1
git clone /path/to/local/repo test
This should reduce the size of the repo as the LFS tracked files will be converted to pointer files. If you want to use the LFS tracked files you need to do a git lfs pull
.
Since git lfs pull
will download all the LFS tracked files in the current checkout, you can use the inclusion and exclusion options to either include or exclude particular files.
For example you can include all pdfs (LFS tracked files) in the repo by
git lfs pull -I "*.pdf"
or exclude them by
git lfs pull -X "*.pdf"
Note that you can clone from the remote repo itself, the cloning of local repo to test repo is just an example to show that the size reduced.