Skip to main content

Large File Storage - LFS

Git LFS configuration

Key Components of the Configuration:

  1. Media Directory as Primary LFS Location

    # Always track everything in the media directory with Git LFS
    media/**/* filter=lfs diff=lfs merge=lfs -text

    This ensures all files in the media folder are tracked with Git LFS, which is your primary location for all large files.

  2. Protection for UI Assets

    # Exclude src/assets/ files from LFS tracking - these are UI assets
    src/assets/**/*.png -filter -diff -merge text
    src/assets/**/*.jpg -filter -diff -merge text

    This keeps your Angular UI assets in regular Git for better developer experience.

  3. Safety Net for Images Outside Designated Areas

    # Safety net: Track large images outside designated folders with Git LFS
    *.png filter=lfs diff=lfs merge=lfs -text
    *.jpg filter=lfs diff=lfs merge=lfs -text

    This catches any image files that might be accidentally placed outside the assets directory. The assets exclusions take precedence over these rules.

  4. Special Handling for Video Files

    # Video files - always track with LFS since they're almost always large
    *.mp4 filter=lfs diff=lfs merge=lfs -text

    Videos are almost always large, so we track them with LFS regardless of location (except in assets).

  5. Design Files Always Use LFS

    # Design files - always track with LFS regardless of size or location
    *.psd filter=lfs diff=lfs merge=lfs -text
    *.ai filter=lfs diff=lfs merge=lfs -text

    Design files are binary and should always use LFS.

Note on Size-Based Filtering

Unfortunately, Git LFS doesn't fully support filtering by file size in the .gitattributes file (the size>20mb syntax I initially tried isn't supported by all Git implementations).

Instead, this configuration:

  1. Uses folder location as the primary determinant (media/**/*)
  2. Applies type-based rules as a fallback
  3. Creates explicit exclusions for UI assets in assets

Best Practice for Your Team

With this configuration, your team should follow these guidelines:

  1. Use the media folder for all large media files (images, videos, etc.)
  2. Keep UI assets in assets to ensure they're tracked with regular Git
  3. Put design files anywhere - they'll be tracked with LFS regardless of location

This approach provides the safety nets you need while maintaining a clean separation between regular Git files and LFS-tracked large files.