Git LFS track folder recursively
Use git lfs track "myfolder/**"
, with quotes to avoid the shell already expanding the pattern. All that the track
command does is to write to .gitattributes
, which in turn uses (almost) the same pattern matching rules as .gitignore
, see the PATTERN FORMAT description.
This way you can track any folders with any subfolder. You want to recursively track folders with "n" number of folder and "m"number of sub-folders. I would recommend doing it this way.
- Find all the files extensions using following command
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u
- and then creating a .gitattribute file and adding git lfs track syntax. This command generates that for you, it tracks all the files and its extensions and creates lfs tracking syntax.
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u | awk '{print $1" filter=lfs diff=lfs merge=lfs -text"}' | sed 's/^/*./'
- Copy paste output to the .gitattribute file and commit.
It works for
- Any number of files and folder.
- Large repo with large number of small files which makes the repo size very big.
- Any number of folder and sub-folders.