Skip to main content

Pre-commit hook to automatically track large files in Git LFS

Project description

git-lfs-autotrack

A pre-commit hook that automatically moves large files into Git LFS when they exceed a configurable threshold.

How it works

When a staged file exceeds its threshold, the hook:

  1. Runs git lfs track <pattern> (e.g. *.json) to add an entry to .gitattributes
  2. Unstages the regular blob and re-adds it as an LFS pointer
  3. Stages the updated .gitattributes
  4. Exits non-zero to abort the commit

Re-run the commit, and it goes through cleanly as an LFS pointer commit.

Requirements

  • Python 3.12+
  • git-lfs installed and on PATH

Usage

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/vainuio/git-lfs-autotrack
    rev: v0.1.0
    hooks:
      - id: git-lfs-autotrack
        args:
          - --max-lines=3000
          - --glob=**/data/*
          - --glob=**/_data/*

Default exclusions

The hook manifest excludes source-code extensions across all major languages (Python, JS/TS, Go, Rust, Java, C/C++, Ruby, PHP, shell, Haskell, Clojure, Elixir, Scala, Lua, HCL, and many more) so that source files are never accidentally moved to LFS.

To override the exclusion list entirely, set exclude in your hook config (this replaces the manifest default):

hooks:
  - id: git-lfs-autotrack
    exclude: '^$'   # exclude nothing — all files are eligible

Or supply your own pattern:

hooks:
  - id: git-lfs-autotrack
    exclude: '\.(py|js|ts)$'

Arguments

Argument Default Description
--max-lines=N 10000 Line threshold for known-text files
--max-bytes=N 10485760 (10 MiB) Byte threshold; applied to all files
--glob=PATTERN (all files) Restrict to files matching this glob (repeatable)

Thresholds

Every file is checked against --max-bytes first. If the file exceeds that limit it is moved to LFS regardless of type.

For files within the byte limit, only text files are checked against --max-lines. Binary and unrecognised files are not tracked unless they exceed --max-bytes.

File-type classification

The hook classifies files using two sources, checked in this order:

  1. .gitattributestext, eol=crlf, or eol=lf → text; binary or -text → binary. Lines with filter=lfs are skipped (already tracked).

  2. Built-in extension defaults:

    Binary Text
    .pdf .7z .bz2 .bzip2 .gz .zip .json .toml .xml .yaml .yml .csv

Files with unrecognised extensions are treated as binary (byte threshold only).

Standalone use

# via uvx (no install required)
uvx git-lfs-autotrack --max-lines=3000 path/to/file.json

# or install into a virtualenv
pip install git-lfs-autotrack
git-lfs-autotrack --max-lines=3000 path/to/file.json

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_lfs_autotrack-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_lfs_autotrack-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file git_lfs_autotrack-0.1.0.tar.gz.

File metadata

  • Download URL: git_lfs_autotrack-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for git_lfs_autotrack-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ef257534b8fd4f42896d4768186c0a2181f4af1958ff3bfce2eb8614ed8cc27a
MD5 daeee9fbadfb38ec9e7ab35250e4d4fe
BLAKE2b-256 873bf3543b01565f77356b2e8209a260d7c78f4dab47b77cc37c2e57751db7b8

See more details on using hashes here.

File details

Details for the file git_lfs_autotrack-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: git_lfs_autotrack-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for git_lfs_autotrack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 acc8733d35fe57121cc9258d43bddd3bb35769efcc0b6d481fe68c33c7151147
MD5 6c4f7bafff0e7e25761768335cd5d9a8
BLAKE2b-256 d22259b91c257d21a35a6e9a691ac7ffdc2e672c5af5a4c0e079edc2c8ed3778

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page