Git - Commit Large Files
Camilo Diaz
Introduction
Git is a great versioning control system that allows you to store and keep history of source code and other files. GitHub is a web application that allows you to create repositories and store your git projects. However, GitHub only supports committing files less than 100MB. There are cases where files are easily over that amount ( i.e obj files ), and you need to keep track of those files. The way to workaround this is using Git Large File system support. You can find all documentation in the given link, but here's an example.
First, make sure to install Git LFS.
Open a terminal and cd to the path where your git repository is located.
For example my project is at /users/cdiaz/MyUnityProject , then execute the command cd /users/cdiaz/MyUnityProject
Once you are in the path, execute the command git lfs track "*.obj"
In the given example, all files with extension .obj will be tracked. I prefer this approach rather than just adding file by file. Sometimes git complains about the file already being tracked, eve if you have never added it to lfs. If you want to track all the png files then just replace the extension with png git lfs track "*.png"
Execute the command git add .gitattributes
At this point Git LFS is tracking all the files and GitHub will accept any obj file larger than 100MB. Now you just need to stage the files in git and push it to the remote repo.
git add file.obj
git commit -m "Add model file"
git push origin main
Previous versions of Git LFS complained about adding files that have been previously staged. This means you staged the files before tracking them. This fix was difficult and it required to rollback some commits and create a new HEAD for your repository. This is not truth for newer versions of LFS. If you are receiving errors related to previous staged files just make sure to upgrade your LFS.