Unity gitignore essentials

17 June 2022

Having a gitignore in your Unity project is almost mandatory if you use Git. Here is the minimum information you need to know to make it work.

Your gitignore will evolve

A “.gitignore” file is a special settings file recognized by Git. It will tell Git how to behave. The main goal of a gitignore file is to save space on your Git repo and to avoid merge conflicts by ignoring files that can be generated.

Unity generates lots of files, and with each new Unity version, their location can change new files can be generated in new folders. So ideally you should keep your gitignore up to date.

If you want to learn more about gitignore in general, check out this article from Atlassian.

Which gitignore to use with Unity

You could write your own, but to save time it’s usually more efficient to take one from internet. Personally, I think that the most comprehensive and up to date gitignore is this one from GitHub. Why? Because a lot of clever people have worked together to come up with it and maintain it.

As of this writing, here is what it looks like:

# This .gitignore file should be placed at the root of your Unity project directory

#

# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore

#

/[Ll]ibrary/

/[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/

# Recordings can get excessive in size

/[Rr]ecordings/

# 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

*.app

# Crashlytics generated file

crashlytics-build.properties

# Packed Addressables

/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets

/[Aa]ssets/[Ss]treamingAssets/aa.meta

/[Aa]ssets/[Ss]treamingAssets/aa/*


The simplest way to download it is to go to GitHub gitignore repo.

Then download the repo by clicking on code -> Download ZIP:

download gitignore from github

Unzip the folder. The gitignore file you want is shown in the image below.
Copy it into your Unity project and rename it exactly “.gitignore”.

unity gitignore location

Where to put the gitignore file in a Unity project

It depends on what you wrote in the file. If you used the one from GitHub, just place it at the root of your Unity Projet. Like in this image. Note that the root of your Unity project is not necessarily the root of your Git repository.

where to put gitignore in unity project

If you were already using Git on this project

If you already added files to your repository, even if you tell Git to ignore them, it continues to follow them. You might prefer to start a new Git repository.

Or you can tell Git to forget those files.

To do that, open the terminal, navigate to the root of your repository and type “git rm -r x”. Where x represents all the folders and files that exists in your git repo and that are also mentioned in the gitignore file.
And then commit.
It should look like this:

how to remove files from git repo


That’s it for the basics about using a gitignore with Unity! I hope you are now up and running 😊


P.S. You might be interested to know that I’m building a plugin for Unity that makes using Git easier.