- Published on
 
Managing 3D Assets Efficiently with Git Hooks and Git LFS
- Authors
 
- Name
 - Beni
 - Tech Lead
 
Managing 3D Assets Efficiently with Git Hooks and Git LFS
Hello, this is Beni, Tech Lead at REALDRAW. In this post, we’ll explore how to efficiently manage 3D assets using Git hooks and Git LFS.
What is Git LFS?
Git LFS (Git Large File Storage) is an extension designed to handle large files efficiently in Git. Git is optimized for text-based files, so managing large binary files (like 3D assets) can cause significant performance issues. Git LFS solves this by storing large files in a separate storage system while keeping lightweight pointers to those files inside the main Git repository.
What is a Git Hook?
A Git hook is a script that runs automatically when certain Git events occur. For example, you can automate tasks such as checking code before a commit or running tests before a push.
Combining Git Hooks and Git LFS
By combining Git hooks with Git LFS, we can automatically manage large files. For instance, you can write a script that checks file sizes before each commit and automatically adds files over a certain size threshold to Git LFS.
Example: A Pre-Commit Script to Automatically Add Large 3D Assets to Git LFS
#!/usr/bin/env bash
set -euo pipefail
# ===== Configuration: 100MB threshold =====
THRESH=$((100*1024*1024))
# Check if git-lfs is installed
if ! command -v git-lfs >/dev/null 2>&1; then
  echo "[pre-commit] git-lfs not found. Run 'git lfs install' first." >&2
  exit 1
fi
# Get list of staged added/modified files
files=$(git diff --cached --name-only --diff-filter=AM -z | tr '\0' '\n')
for f in $files; do
  [ -f "$f" ] || continue
  size=$(stat -c%s "$f" 2>/dev/null || stat -f%z "$f")
  if [ "$size" -ge "$THRESH" ]; then
    echo "[LFS] '$f' is $size bytes (>= $THRESH). Tracking with Git LFS..."
    git lfs track -- "$f" >/dev/null
    git add .gitattributes "$f"
    echo "[LFS] Tracked + re-staged: $f"
  fi
done
exit 0
This script runs before each commit, automatically adding any staged files larger than 100MB to Git LFS.
How to Use the Script
- Save the script above as 
pre-commit. - Place it in your repository’s 
.git/hooks/directory. - Grant execution permission: 
chmod +x .git/hooks/pre-commit(Linux/Mac) - Now, whenever you make a commit, the script will automatically detect large files and add them to Git LFS.
 
⚙️ Make sure to run
git lfs installin your repository before using this script.
At REALDRAW, this script has significantly improved our efficiency in managing 3D assets across multiple projects.
Conclusion
By leveraging Git hooks and Git LFS, teams can manage 3D assets more effectively. Automated scripts help simplify large file management and reduce potential collaboration issues caused by oversized binary files.
We hope this approach helps streamline your own project workflows. Thank you for reading!