Git does not automatically move files back to normal Git storage after you untrack them from LFS. Here’s what happens when you untrack a file:
- Git LFS still stores the file
- The LFS object (the actual file) remains in
.git/lfs/objects
locally and on GitHub’s LFS storage. - Git still tracks the file as a pointer file (a small text file with a hash).
- The LFS object (the actual file) remains in
- The file is NOT automatically added to normal Git storage
- Untracking only stops future commits from using LFS, but previously committed LFS objects remain in history.
How to Move a File Back to Normal Git Storage
To store the file as a normal Git file instead of an LFS pointer:
1. Untrack the file from LFS
git lfs untrack "path/to/file"
Then, remove the .gitattributes
entry related to it.
2. Remove LFS-tracked file from Git history
Run:
git rm --cached "path/to/file"
This removes the LFS reference but keeps the file locally.
3. Recommit the file as a normal Git file
git add "path/to/file"
git commit -m "Re-adding file as a normal Git file"
git push origin main
Now, Git will store the full file instead of an LFS pointer.
4. Clean Up LFS Storage (Optional)
If you no longer need the file in LFS:
git lfs prune
To fully remove it from GitHub’s LFS storage, you need to rewrite history using git filter-repo
and force push.
How to completely remove the file from Git LFS
1. Clone a fresh copy:
git clone --mirror https://github.com/YOUR-USERNAME/YOUR-REPO.git
cd YOUR-REPO.git
2. Run the git filter-repo command:
git filter-repo --path "path/to/file" --invert-paths
3. Push the cleaned repo back to GitHub:
git push origin --force --mirror