Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to delete multiple lfs files

We are working on an unreal project and thinking about using bitbucket/source tree. But I fear lfs wont give us enough control. I tested uploading multiple lfs files, but it seems I can only delete them 1 by 1. So if I upload 200 texture files and need to delete 100 of them, I can only delete them 1 by 1?

1 answer

0 votes
Syahrul Atlassian Team Jan 11, 2022

Hi @Evan Robinson 


We don't have a feature to bulk delete the LFS files at this moment, but it's possible to delete them via the API. We do have an existing feature request on this, please Vote & Watch so that you'll get an update whenever we have any at:

While we don't have a UI feature to bulk delete the LFS files, it's possible to delete the LFS files via API, and by using the API you can create a script to bulk delete the LFS files.

I do have a script you can use, but do note that we don't officially support this script, so please use it at your own risk and tweak it as you wish.

  1. You need to get the list of the LFS OID files first, so run the following commands in the repositories
    git lfs ls-files -l | awk -F " " '{print $1}' > lfs.txt

    This will print and store the LFS OID in text files of lfs.txt

    • Use these commands to list out the files and OID so you can filter out which files to keep or and remove the OID from lfs.txt list
      git lfs ls-files -l 
  2. Once done, copy the following script and save it as .sh. Then ensure that it has all the necessary permission to execute and simply run the commands to bulk delete your LFS files
    while read line || [ -n "$line" ]
        echo "File number : $i"
        echo "LFS Object ID (OID) : $line" 
        cmd=$(curl -s -w "\nHTTP Code:  %{http_code}\n" --user $credential -X DELETE "<Workspacename>/<Repositoriesname>/lfs/$line")
        echo "Response : $cmd"
        echo ""
    done < $file
    echo ""
    echo "Total LFS Object ID in $file :" 
    grep -c "" $file

I hope this helps


Suggest an answer

Log in or Sign up to answer

Atlassian Community Events