DEV Community

Cover image for Git LFS track folder recursively
Prabesh Thapa
Prabesh Thapa

Posted on

Git LFS track folder recursively

If you want to recursively track folders with "n" folder and "m" sub-folders. I would recommend doing it this way.

  1. Find all the files extensions using following command
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u
Enter fullscreen mode Exit fullscreen mode
  1. 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/^/*./'
Enter fullscreen mode Exit fullscreen mode
  1. Copy paste output to the .gitattribute file and commit.

It works for

  1. Any number of files and folder.
  2. Large repo with large number of small files which makes the repo size very big.
  3. Any number of folder and sub-folders.

Top comments (0)