CodeBlanks Logo Icon CodeBlanks

lfs track

Learn to define patterns with git lfs track.

Pattern tracking with lfs track

To specify which file types Git LFS should track, use the git lfs track "<pattern>" command. For example, define a pattern to track all .psd or .mp4 files with LFS. This command automatically writes the appropriate filter rule to .gitattributes at repository root.

git lfs track "*.psd"
git lfs track "*.mp4"

Any file matching the specified pattern will subsequently be handled by LFS automatically.

Importance of .gitattributes

The .gitattributes file must be staged and committed to the Git repository. When committed, teammates who clone the repo automatically know which files are tracked by LFS. To see which patterns are currently tracked, run git lfs track without arguments.

git add .gitattributes
git commit -m "Add LFS tracking rules"

This ensures that every team member handles large files consistently under the same rules.

Practice Write PSD rule to .gitattributes

Write *.psd filter=lfs diff=lfs merge=lfs -text to .gitattributes and verify with cat .gitattributes.

Starter code

terminal
git init -q -b main
# *.psd dosya desenini LFS filtresiyle .gitattributes dosyasina ekle

# dosya icerigini bas

Sample solution

terminal
git init -q -b main
echo "*.psd filter=lfs diff=lfs merge=lfs -text" > .gitattributes
cat .gitattributes

Expected output

*.psd filter=lfs diff=lfs merge=lfs -text

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Where is the tracking rule saved when git lfs track "*.zip" is executed?

  • At the very last line of the .gitignore file
  • In the .gitattributes file at repository root Correct answer
  • In the user's home directory .bashrc file
  • In the remote section of the .git/config file

Explanation: git lfs track writes file patterns and associated LFS filter rules to the .gitattributes file.

2 Track file pattern with LFS

Question
git lfs ____ "*.mp4"
Answer
git lfs track "*.mp4"

Explanation: git lfs track "<pattern>" registers the specified file extension or path with Git LFS.

3 Tracking mechanism

Term Meaning
git lfs track Defines file pattern for LFS
.gitattributes File that stores LFS rules
"*.psd" Directs specified extension to LFS
git add .gitattributes Includes LFS rules into repository

All lessons in Expert