Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git LFS track folder recursively

Tags:

git

git-lfs

Is it possible to track recursively all files contained in a folder and its subfolders with Git LFS ?

I would like to do something like this :

git lfs track myfolder/*
like image 709
csa Avatar asked Oct 06 '22 20:10

csa


People also ask

Where are Git LFS objects stored?

Git LFS objects can be large in size. By default, they are stored on the server GitLab is installed on.

What is Git LFS prune?

DESCRIPTION. Deletes local copies of LFS files which are old, thus freeing up disk space. Prune operates by enumerating all the locally stored objects, and then deleting any which are not referenced by at least ONE of the following: ○ the current checkout.


2 Answers

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.

like image 236
sschuberth Avatar answered Oct 21 '22 04:10

sschuberth


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.

  1. Find all the files extensions using following command
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u  
  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/^/*./'
  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.
like image 3
Prabesh Thapa Avatar answered Oct 21 '22 04:10

Prabesh Thapa