Git LFS
All about Git LFS
What is Git LFS
Git LFS is an extension which allows us to place files of large storage sizes into version control
It does this by locally replacing the files themselves with text pointers to them and storing the actual files on a remote server
When to use Git LFS?
It is advisable to use git LFS when you have large files in your repository and/or a lot of binaries
Why use it?
Git LFS reduces the impact of large files in your repository by downloading the relevant versions of them lazily.
This helps save storage space and improves efficiency for developers
Giting started
Environment setup
Download git LFS here: https://git-lfs.github.com/
- You will also need access to your terminal to run some commands
Initializing Git LFS via the command line
$ git lfs install
- Run once per user account
Adding files to be tracked by Git LFS and setting up your .gitattributes file
$ git lfs track "*.file-extension"
ex: git lfs track "*.jpeg"
- This tells git LFS to manage all your jpeg files in the given directory
We can tell git LFS which file types to track using multiple of these command or we can directly edit the .gitattributes file in the root of the repository directory
-
Here is a good resource outliting the structure of the .gitattributes file with an example: https://rehansaeed.com/gitattributes-best-practices/
-
Generally the lines following the format below will be needed to track various file types using git LFS:
- *.pdf filter=lfs diff=lfs merge=lfs -text
-
It is also noramlly a good idea to track Git LFS file extensions by grouping them by type. For example: docuements, images, fonts, etc.
-
There is a sample .gitattributes file template with common extensions to help you get started in within this Git LFS folder called "Gitattributes-Sample-Template.md"
- You may choose to use this as a starting point by coping the contents of the mardown file into a new file at the root of your repo
- Ensure to call your actual file .gitattributes
finally, we also need to make sure that the .gitattributes file is being tracked:
$ git add .gitattributes
- Make sure that the .gitattributes file is also moved into existing branches that have been checked out from main before its creation (this will not be an issue for any braches created thereafter)
That's it! Now just continue to follow you git flow and process as you normally would by adding, commiting, and pushing up your current changes
Git LFS and Azure DevOps
Git LFS is is fully supported and free in Azure DevOps Services including Azure Repos
It can easily be used via the integrated terminal in VS Code or your favorite IDE
Git LFS restrictions to keep in mind
(TLDR from the Microsoft docs)
- Every Git client used by your team must install the Git LFS client and understand its tracking configuration.
- Git cannot merge the changes from two different versions of a binary file even if both versions have a common parent.
- Always pull the latest copy of a binary asset before beginning work.
- Azure Repos does not support using SSH in repos with Git LFS tracked files.
- If a user drags and drops a binary file via the web interface into a repo which is configured for Git LFS, the binary will be committed to the repo and not the pointers that would be committed via the Git LFS client.
- File size limit is 50 GB.
- One file upload time limit is 1 hour.
Resources and Tutorials to Help You Git Started
https://www.atlassian.com/git/tutorials/git-lfs
https://docs.microsoft.com/en-us/azure/devops/repos/git/manage-large-files?view=azure-devops
https://dzone.com/articles/git-lfs-why-and-how-to-use
https://microsoft.github.io/code-with-engineering-playbook/source-control/git-guidance/git-lfs-and-vfs/
https://andrewlock.net/creating-a-git-repo-with-azure-repos-and-trying-out-git-lfs/
https://www.youtube.com/watch?v=xPFLAAhuGy0