How do I add a file type to Git LFS tracking?
To add a file type to Git LFS tracking, you must add an entry in the .gitattributes file in your repository
What is Git LFS?
Git LFS (Large File Storage) keeps big files — PLC projects, images, videos, binaries — out of the normal Git history. In your repo, they're replaced by tiny pointer files, and the real content lives on the LFS server. Result: faster clones, smaller history, same versioning.
You can find more information about Git LFS in our Documentation.
The .gitattributes pattern
Your .gitattributes file uses this style:
### *.zip
*.[zZ][iI][pP] filter=lfs binary
The ### line is a comment header. The bracketed letters ([zZ], [iI], [pP]) make the match case-insensitive, so file.zip, FILE.ZIP, and File.Zip are all caught.
Copy this pattern for any new extension (examples):
|
Extension |
Add this |
|
.psd |
|
|
.bin |
|
Getting Started
You have three options. Pick based on your goal:
Option |
What it does |
Shrinks repo size? |
Risk |
|
A. Track going forward |
Future commits go to LFS; old files stay as-is |
❌ No |
None |
|
B. Rewrite all history |
Moves every old version into LFS, in place |
✅ Yes |
High |
|
C. Archive old repo, start fresh |
New clean repo with LFS; old repo preserved read-only |
✅ Yes |
Medium |
Option A — Track going forward (safest)
Best for: Adding to LFS prior to repo size being an issue
- Switch to the shared branch (e.g. main), pull latest.
- Add the new entry to .gitattributes.
- Commit and push. Message: Track *.psd files with Git LFS.
- Let everyone else know to Pull a fresh copy of the repo
Done. New .psd files go to LFS; older versions stay where they are.
Option B — Rewrite all history (coordinated)
Best for: When you genuinely need to reduce repo size on disk.
⚠️WARNING - This could break branch and PR references in history, Option C is recommended, as a safer option.
Before you start:
- 📦 Back up the repo:
git clone --mirror <repo-url> backup.git - 📅 Schedule a maintenance window
- 📢 All collaborators must push their work and stop pushing during the migration
- 🔓 Be ready to temporarily disable branch protection rules
Steps:
- Make a fresh clone in a separate folder (don't use your daily workspace):
-
git clone <repo-url> repo-lfs-migrationcd repo-lfs-migrationgit fetch --all
-
- Add the new entry to .gitattributes on the default branch, commit.
- (Optional) Preview impact:
-
git lfs migrate info --include="*.psd" --everything
-
- Run the migration across all branches and tags:
-
git lfs migrate import --include="*.psd" --everything
-
- Review .gitattributes and remove any duplicate line.
- Force-push everything:
-
git push --force-with-lease --allgit push --force-with-lease --tags
-
- Tell everyone to re-clone the repo. Old clones will be very hard to reconcile.
⚠️ Open PRs and code reviews referencing old commit hashes may break. Give reviewers a heads-up.
Option C — Archive old repo, start fresh (cleanest break)
Best for: When you don't need full Git history in the active repo and want to avoid force-pushes.
|
✅ Use Option C if... |
❌ Skip Option C if... |
|
Old PRs and commit links should stay readable, not break |
Lots of tooling/scripts assume the current repo URL |
|
You don't lean on git blame or old history day-to-day |
Day-to-day work depends on full Git history |
|
You want to avoid touching branch protection or force-pushing |
Before you start:
- Ask the team to merge or close any open PRs they care about
- List everything pointing at the current repo URL: CI/CD, deployments, docs, dependent repos, dashboards, bookmarks. You'll update all of them.
Steps:
- On your Git host, create the new (empty) repo. Use a suffix like -v2 or -lfs, or a fresh name.
- Clone the old repo into a clean folder, then drop its history:
-
git clone <old-repo-url> new-repocd new-reporm -rf .git
-
- Initialize fresh:
-
git initgit lfs install
-
- Confirm .gitattributes came over correctly. Add any new entries.
- Stage, commit, push:
-
git add .git commit -m "Initial commit (migrated from <old-repo-name>)"git remote add origin <new-repo-url>git push -u origin main
-
- Match the new repo's settings to the old one: branch protection, reviewers, webhooks, deploy keys, secrets, integrations.
- Archive the old repo. Most Git hosts offer this as a one-click setting — it makes the old repo read-only. Old PRs, issues, and commit links remain accessible.
- Update everything pointing at the old URL.
- Tell everyone to clone the new repo.
⚠️ Open PRs don't carry over to the new repo. Recreate any in-progress work as branches in the new repo before archiving. Some Git hosts can transfer issues — check before archiving if you want them moved.
Verifying it worked
- Web App: look for an "LFS" badge next to the file in the repo
- Local command, list everything in LFS:
git lfs ls-files
-
Open .gitattributes locally and confirm your entry is there in the right style.
Troubleshooting
|
Problem |
Fix |
|
Push rejected on a protected branch |
Temporarily disable branch protection, push, re-enable. |
|
LFS asking for credentials or rejecting uploads |
Run git lfs env to check the endpoint. Some hosts need a personal access token, not a password. |
|
Teammates' branches broke after a history rewrite |
Expected after Option B. They re-clone, or save work aside and re-apply. (Consider Option C next time.) |
|
Repo size didn't shrink on the server |
Most hosts don't reclaim storage until garbage collection runs (hours/days). Some need a support request. |
Command reference
Used in Scenario 2 and Scenario 3 Options B and C. Everything else is desktop-client only.
|
Command |
What it does |
|
|
Lists files currently in LFS |
|
|
Previews how much space an extension uses (no changes) |
|
|
Moves existing files on a specific branch into LFS |
|
|
Moves existing files across all branches and tags into LFS |
|
|
Safely force-pushes a rewritten branch |
|
|
Shows your LFS configuration |