0
0
Gitdevops~5 mins

Git LFS for large files - Commands & Configuration

Choose your learning style9 modes available
Introduction
Git LFS helps you manage very large files in your Git projects. It stores big files outside your main repository to keep it fast and small.
When you want to add large images or videos to your project without slowing down Git operations.
When your project has big data files that change often and would make cloning slow.
When you want to share large files with your team but keep your repository size manageable.
When you need to track large binary files that Git cannot efficiently handle.
When you want to avoid hitting Git hosting limits on repository size.
Commands
This command sets up Git LFS on your computer so Git can handle large files properly.
Terminal
git lfs install
Expected OutputExpected
Git LFS initialized.
This tells Git LFS to track all files ending with .psd (Photoshop files) so they are stored outside the main Git repository.
Terminal
git lfs track "*.psd"
Expected OutputExpected
Tracking '*.psd'
Adds the .gitattributes file created by git lfs track to your staging area so Git knows which files use LFS.
Terminal
git add .gitattributes
Expected OutputExpected
No output (command runs silently)
Adds the large file design.psd to the staging area. Git LFS will handle this file specially.
Terminal
git add design.psd
Expected OutputExpected
No output (command runs silently)
Commits the changes including the large file tracked by Git LFS to your local repository.
Terminal
git commit -m "Add large design file with Git LFS"
Expected OutputExpected
[main abc1234] Add large design file with Git LFS 2 files changed, 2 insertions(+) create mode 100644 .gitattributes create mode 100644 design.psd
Pushes your commit and the large file to the remote repository. Git LFS uploads the large file separately.
Terminal
git push origin main
Expected OutputExpected
Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 1.23 MiB | 1.23 MiB/s, done. Total 3 (delta 0), reused 0 (delta 0) Uploading LFS objects: 100% (1/1), 1.00 MiB | 1.00 MiB/s, done. To https://github.com/example/my-app.git def5678..abc1234 main -> main
Key Concept

If you remember nothing else from this pattern, remember: Git LFS stores large files outside your main Git repository to keep it fast and efficient.

Common Mistakes
Not running 'git lfs install' before tracking files
Git LFS won't be properly set up, so large files won't be handled correctly.
Always run 'git lfs install' once before tracking large files.
Forgetting to add and commit the .gitattributes file
Other users or systems won't know which files use Git LFS, causing errors or large files to be stored in Git.
Add and commit the .gitattributes file created by 'git lfs track' to your repository.
Tracking files after adding them to Git without Git LFS
Files already in Git won't be converted to LFS automatically, keeping the repo large.
Track files with Git LFS before adding them to Git.
Summary
Run 'git lfs install' once to set up Git LFS on your machine.
Use 'git lfs track' to specify which large files Git LFS should manage.
Add and commit the .gitattributes file so Git knows about LFS tracking.
Add and commit your large files normally; Git LFS handles them behind the scenes.
Push your commits; Git LFS uploads large files separately to keep your repo small.