I came across a problem when using Git with Unity. Git has a file size limit of 100 MB. This will make uploading things like large asset files an issue. That is when I came across Git LFS. This is an add-on that will allow you to save large files.
To use Git LFS
- download the extension from here => https://git-lfs.github.com/
- Now that it is installed go to the file of the Unity project you have connected to your git repository and open git bash there
- Now install Git LFS using the command “git lfs install”
- Now you will want to create a .gitattributes file that will track the files you want Git LFS to manage
- Type “git lfs track “*.psd”” to create the file
- Now you can go here => https://thoughtbot.com/blog/how-to-git-with-unity to find a list of files that you will want lfs to track. Copy those and add them to your .gitattributes file.
- Now make sure you commit this file
- Now you can add any assets you want to your unity project
- If you have existing files in your repository you may need to migrate them to Git LFS => https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-migrate.1.ronn?utm_source=gitlfs_site&utm_medium=doc_man_migrate_link&utm_campaign=gitlfs
- Type “git lfs migrate info” and it will bring up files you have that can be converted over.
- Now you can use “git lfs migrate import” on these files
- The last thing that might happen when you migrate your files and commit that change is that you will load your scene in unity and all your assets in your scene are gone. You will get an error saying it failed to load because it was serialized with a newer version of unity.
- If this happens you will have to go through the commit process again and use “git lfs pull” => https://github.com/git-lfs/git-lfs/issues/2594
- type “git lfs pull origin main”
- check your status to make sure you are up to date.
- type “git lfs push origin main”
This should fix that problem and you should be good to go.