Search Unity

Git -- .gitignore What it really does?

Discussion in 'Editor & General Support' started by duojet, Aug 11, 2019.

  1. duojet

    duojet

    Joined:
    Jan 23, 2019
    Posts:
    6
    I read that it is best practice to create a .gitignore file when working with a Unity project in a repository. This appears to ignore certain specified files. Why the need for this? Can anyone explain what exactly .gitignore is doing and why it is needed to ignore certain files. I cannot find a good answer for this (at least one I understand).

    Thanks!
     
  2. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,665
    Last edited: Aug 11, 2019
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    And to provide a practical example, here's a visual breakdown of the contents of the project folder for my game:

    upload_2019-8-10_22-7-33.png

    Everything in the red outlined area is the contents of the Library folder, which is stuff that Unity generates, and can safely be deleted. Everything else is the stuff I actually authored that's part of the game. In my case, of the 13 GB of contents in my project folder, only 6GB is actual content I care about. the .gitignore file excludes all that junk in Library from getting into my repo.

    Another useful thing is that you can granularly exclude certain kinds of files from being added to the repo. For example, the big bunch of purple stuff in this image represents LightingData.asset files:

    upload_2019-8-10_22-10-20.png

    Those files can be really big. The largest of mine is about 250 MB. That's beyond the max file size I can add to the repo, so I use .gitignore to prevent any LightingData.asset files from being added to git. This keeps the repo size down, as well as prevents files that are too large from being added to the repo (which would result in push errors later). LightingData.asset files are generated by Unity, so it's not important to me to have those in source control. It's a little annoying if I have to load the project onto a new computer, as those files will need to be generated again, but that rarely happens in my project. Note that you can also use GIT Large File Storage to store large files like this, but that was just eating up all of my storage, so I opted not to use it. (Git LFS isn't a great choice for large files that change frequently, as every version of that large file remains in the repo, inflating its size very quickly.)
     
  4. duojet

    duojet

    Joined:
    Jan 23, 2019
    Posts:
    6
    Thanks so much these answers are very helpful!! The key I believe is we are using .gitignore to ignore the set files that Unity uses. Everything I author (files I am adding or deleting) is being tracked by git. Makes perfect sense!!