Skip to content

Instantly share code, notes, and snippets.

@entelecheia
Created June 23, 2023 06:04
Show Gist options
  • Save entelecheia/35a762ae1b999ac6745f9b937c52c33e to your computer and use it in GitHub Desktop.
Save entelecheia/35a762ae1b999ac6745f9b937c52c33e to your computer and use it in GitHub Desktop.
How to Uninstall Git Large File Storage (LFS)

How to Uninstall Git Large File Storage (LFS)

Git Large File Storage (LFS) is an open-source Git extension for versioning large files. It's a great tool for handling large files, but there might be situations where you want to uninstall it from your repository. Here is a step-by-step guide to help you through this process:

1. Commit and Push Everything

Before you start, make sure to commit and push all your changes to the remote repository. This ensures that no work is lost during the LFS uninstallation process.

git commit -am "Your commit message"
git push origin

2. Remove Git Hooks

Next, you'll want to remove the Git hooks related to LFS. You can do this using the git lfs uninstall command. This will remove any hooks from your local repository that are associated with LFS.

git lfs uninstall

3. Update the .gitattributes File

You'll need to manually remove the LFS configurations from the .gitattributes file. This file is in the root of your repository. It specifies the file types that LFS should track. Delete the lines associated with the files you want to remove from LFS.

4. List All LFS Files

Next, we need to get a list of all the files tracked by Git LFS. Use the following command to write this list into a text file:

git lfs ls-files | sed -r 's/^.{13}//' > files.txt

5. Untrack Files from LFS

Now, for each file in the files.txt, we will run git rm --cached to untrack these files from Git without deleting them from your local system.

while read line; do git rm --cached "$line"; done < files.txt

6. Re-add the Files to Git

After untracking these files, we need to re-add them to Git to make sure they are still under version control.

while read line; do git add "$line"; done < files.txt

7. Commit and Push Everything

Add the .gitattributes file to the commit, then commit the changes with a suitable commit message. After that, push these changes to your remote repository.

git add .gitattributes
git commit -m "unlfs"
git push origin

8. Confirm LFS Files are Removed

You can check that there are no LFS files remaining in your repository using the git lfs ls-files command. If no files are listed, then you've successfully removed all LFS files.

git lfs ls-files

9. Remove LFS Junk

Lastly, you can remove the LFS related junk in your repository using the following command:

rm -rf .git/lfs

10. Wrapping Up

Now you've successfully uninstalled Git LFS from your repository. Note that this process only removes LFS from your local repository. Any files stored in LFS on your remote repository (like BitBucket Git LFS storage) will still exist until they are manually removed.

Be sure to follow the relevant documentation of your specific git host to understand how to manage LFS files on the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment