Git LFS (Large File Storage) is a Git extension that helps manage large files more efficiently by storing them outside the main Git repository. Here's a step-by-step guide on how to use Git LFS:
Before you start, make sure you have Git LFS installed on your system. You can download it from the official website: Git LFS Installation
-
Initialize Git LFS:
-
Navigate to your Git repository on your local machine using the terminal.
-
Run the following command to initialize Git LFS:
git lfs install
-
-
Track File Types with LFS:
-
Decide which file types you want to manage with Git LFS (e.g., large PDFs, images, binaries).
-
Run the following command for each file type you want to track:
git lfs track "*.pdf"
Replace
*.pdf
with the file extension you want to track. -
-
Commit and Push Changes:
-
Add, commit, and push your changes as you normally would:
git add . git commit -m "Add large files using Git LFS" git push origin main
-
-
Pulling Changes:
-
When you clone a repository that uses Git LFS, the large files are not automatically downloaded. Run the following command to fetch and download them:
git lfs pull
-
-
Pushing Changes:
- When pushing changes that include large files, Git LFS will automatically upload them. You don't need to take any additional steps.
To check the status of your Git LFS configuration and tracked files, you can use:
git lfs status
If you want to stop tracking a file with Git LFS, you can use:
git lfs untrack "*.pdf"
Replace *.pdf
with the file extension you want to stop tracking.
-
Make sure to include the
.gitattributes
file generated by Git LFS in your commits, as it contains information about which files are tracked using LFS. -
Ensure that all collaborators working on the repository have Git LFS installed.
Keep in mind that Git LFS is designed for large binary files, and using it for source code files is generally unnecessary. Use it selectively for files that need versioning but are too large for traditional Git handling.