You probably found this page because LFS storage quotas suck absolute balls and GitHub's response to the question to "how can I delete old unneeded files from your servers?" is "Fuck off and get fucked, loser." (Slightly paraphrased)
I refuse to delete my entire repository just to clear up LFS storage. Instead I removed all LFS files from my Git history and uninstalled LFS.
Command to list all commits with LFS files (basically a dry run):
git checkout main
git filter-branch --prune-empty --index-filter 'git lfs ls-files $GIT_COMMIT'
This command lists all commit sha1's and the LFS files contained. Use git checkout <sha1>
and then back up files you want to keep.
Command to delete the files:
git checkout main
git filter-branch --prune-empty --index-filter 'git lfs ls-files --name-only $GIT_COMMIT | git update-index --remove --stdin' -f
If this somehow messed up your repository, you can still get back to a good (/ less bad) state.
# restore backup (replace 'main' with your primary branch name)
git reset --hard original/refs/heads/main
Otherwise run:
git lfs uninstall
Also remove lfs entries from your .gitattributes
file. Copy any files you want to commit from your backups (mind the GitHub 100 MB file size limit).
git add .
git commit -m "Stop using LFS"
git push -f
Evidently this will rewrite all your commit history so you need permission to force push to your main branch.