One thing we've all learned, usually the hard way, is the importance of the .gitignore file when doing projects in Unity, Unreal, or most other game engines. There are just tons of auto-generated files that you do not want in your commits, because they will break things.

With Unity, the Library directory is one example. This entire directory should not be in your repository, because it contains files that are autogenerated on everyone's computer. Overwriting them with Library files from another copy will clobber all kinds of things in your scene; not while not overwriting them will prevent you from committing other changes because Git thinks you have merge conflicts. It's essential that Library/ be untracked, that is, ignored completely by Git.

Symptoms of having your Library accidentally in your repository include:

You can't check out or pull any changes, because you get lots of errors like this:

/[LI]brary/ means to ignore Library. The trailing slash means only match directories named Library, not regular files. The square brackets match either capital L or lower-case l, so either Library or library.

The prefix slash is important too, and this is where problems can come from. The leading slash only matches patterns relative to the .gitignore file. So if your .gitignore is in the top level of your Unity project, it will match the Library/ directory, but not, say, Assets/Models/Environments/Town/Library/.

This is fine if your .gitignore is place in the top level of your Unity project.

You may have a directory structure like this, however:

OurGame/

README

.gitignore

ArtStuff/

Concept Art/

MayaFiles/

Writing

OurGame_UnityProject

Assets

Library

since .gitignore is above the level where the Unity project is, the Library directory won't be matched. It'd have to be [code]/OurGame_UnityProject/[Ll]ibrary/[code] to match it.

An easy solution is to put the .gitignore into the Unity project directory. You can have it in both places. A .gitignore in any subdirectory will add on to and override anything set in parent directories.

For more about the .gitignore syntax, the shell globbing and regex syntax it uses, etc: