.gitignore not ignoring files in Unity Project

My .gitignore file is in the main GitHub repo folder, in which the entire Unity project also is. It is a slightly modified version of the default one given by Unity, nwhich doesn’t work either. Problem is the .gitignore file isn’t doing what it should be doing. The following is what my .gitignore file looks like and it’s what I mainly want to ignore:

# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
**/Library/
**/[Tt]emp/
**/[Oo]bj/
**/[Bb]uild/
**/[Bb]uilds/
**/[Ll]ogs/
**/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
**/[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!**/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# **/[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
**/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

I’ve tried all of the following to ignore and none of them work: **/[Ll]ibrary/, **/Library/, [Ll]ibrary/, /[Ll]ibrary/

The ones with the double asterisks do ignore 8000+ files that I untracked with git rm -r --cached, but they don’t ignore any changes made in e.g. Library/ArtifactDB or Library/PackageManager/ProjectCache.

How do I get my .gitignore to ignore these files?

Until you git rm tracked files, you can ignore them all day long but they are part of your repo, so changes are picked up.

If you originally inadvertently committed stuff in Library, just git rm ALL of it because that stuff will grow your repo so fast you’ll end up with a giant ball of junk.

In fact, if you’re early in the project I would just abandon the entire repository in place, keep it as an archive, then set up a new repo with the gitignore file already added, then add the Assets, ProjectSettings and Packages folder and start over with a new repo. To me it is not worth carrying hundreds of megabytes of old Library crud around from earlier commits!

ALSO: good on you for getting source control going. Too many people come in here saying “MY PROJECT IS EFFED, WHAT DO I DO?!”

So here are some extra boilerplate git notes for you:

Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

As far as configuring Unity to play nice with git, keep this in mind:

https://discussions.unity.com/t/736093/3

Here’s how I use git in one of my games, Jetpack Kurt:

https://discussions.unity.com/t/807568/3

Using fine-grained source control as you work to refine your engineering:

https://discussions.unity.com/t/826718/2

Share/Sharing source code between projects:

https://discussions.unity.com/t/719810/2

Setting up an appropriate .gitignore file for Unity3D:

https://discussions.unity.com/t/834885/5

Generally setting Unity up (includes above .gitignore concepts):

https://thoughtbot.com/blog/how-to-git-with-unity

It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.

“Use source control or you will be really sad sooner or later.” - StarManta on the Unity3D forum boards

3 Likes

Good idea about the usb drive I never thought of that.

What do you guys mean by this? Im trying to move my game into a repository that was made for the first time and other then the github readme and github ignore (unity) file has no commits so I have the chance to get this right the first time. but whatever mystic code this is you’ve shared here is very hard to decipher. I’ve already watched 3 videos of people just breezing through this step but, everytime I try it a library file, that’s too big, tries to upload and github warns me and I cancel the commit. So I know something isn’t right here because all of the files in library should be ignored.

Good intuition. You should start a fresh thread with a caption / title something along the lines of:

git is not ignoring my Library/ folder even though I have it in my .gitignore file

And then post the contents of your .gitignore file. :slight_smile:

Please don’t necro-post. If you have a new question, make a new post. It’s FREE!!

the question pertains to your response so this shouldn’t require a new thread. An answer and clarification of what is meant by, “Until you git rm tracked files” may even help others in the future so they can just reference this thread as well, when it comes up on a google search. how I found it.

The thread was also last posted in may 2024 nearly 3 years after your exchange in 2021. I looked before posting so I have no qualms posting another response 8 months later when the OP waited 3 years originally… Especially if it helps clarify one darn line of text that’s apparently explains the whole issue if you already know what it means…

But to answer your question, my file looks like the default gitignore file as provided by github circa jan 24th 2025.

The actual quote I made was:

… and it has to do with how to STOP tracking changes to a file that you are already tracking and no longer wish to track.

It does not remove a file from the repo and thus it has nothing whatsoever to do with files that are already committed and too large for github, which was the start of your post here:

You have cross-connected two things that are completely unrelated.

To successfully disregard files, 100% of that work must occur via correct .gitignore and thus has absolutely NOTHING to do with git rm

I am not prepared to teach you git via this little tiny box, so if you have an actual problem, again I urge you to report it like any other problem in a fresh thread.

This is a handy template to report issues with:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation (or git documentation, as the case may be) that you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post code, only post the relevant code and always use the format button above. Do not post photographs of code.

Sorry, didn’t mean to confuse anyone with the extra detail talking about my own problem. The file gets caught because its too big, but the whole library folder shouldnt be uploading anyways. so in a way I got lucky that a totally erroneous library file got made at some point, that is over the github limit. it stopped me from uploading a bunch of junk.

I did find my problem though and maybe this will help others.

-It was a stupid admin mistake and the gitignore file was stored in a folder above the unity project folder (I thought it would filter down). But, apparently the gitignore file needs to be stored in the exact same place as the Library folder and other unity folders that it’s trying to ignore. who knew… probably a programmer… lol

No Idea if that would help the OP but, I get the feeling that a few of these threads Ive run across about the gitignore not working properly may just be that but, then everyone is too embraced to come back and update their topic because yeah, wow, what a silly mistake to make.

Thanks for the follow up though

1 Like