16

I see this command listed on the Git LFS website and documentation:

git lfs track "*.psd"

I have several file types in my project that I want to track with LFS, and will want to track all these same file types in future projects. I would like to be able to paste a single command to track all these extensions, is this possible?

J Garcia
  • 806
  • 1
  • 7
  • 17

2 Answers2

31

After some experimentation I found this was doable by providing multiple arguments:

git lfs track "*.jpg" "*.png"

This will track both jpg files and png files

J Garcia
  • 806
  • 1
  • 7
  • 17
2

I figured out a trick that allows you to store the trackings in a file, which is way easier to manage for bigger projects.

Step 1: Create a text file a list of your trackings, like this:

"*.jpg"
"*.png"

I named mine .gitlfstracks

Step 2: Bulk import trackings from that list file, like this:

cat .gitlfstracks | xargs git lfs track

cat - prints a file to screen

| - redirects the output to another application

xargs - Runs a command over each line of an input

git lfs track - The standard command to track a file

Here is my current list, fyi: https://gist.github.com/bdombro/a1883d8a2cd0938ef798147ba66ecc00

bdombro
  • 1,251
  • 11
  • 17
  • wow nice list! Thanks for this tip, this would definitely be a better workflow when you need a catchall for a lot of file types. – J Garcia May 24 '18 at 02:17
  • 1
    Thanks! Any chance you could thumbs up my answer if ya like it? :-) – bdombro May 26 '18 at 13:01
  • 1
    I think the `.gitattributes` file is set up to do this, actually. If you try J Garcia's solution and then check the `.gitattributes` file, you'll see how it works. The instructions at `https://git-lfs.github.com/` say that you then have to make sure the `.gitattributes` file itself is tracked: `git add .gitattributes`. – John Jan 15 '20 at 22:00