.gitignore for Unity

/Library/ /Temp/ /Obj/ /Build/ /Builds/ /Logs/ /UserSettings/ *.csproj *.sln

A Unity .gitignore ignores the folders the editor rebuilds at the project root (Library/, Temp/, Obj/, Logs/, UserSettings/), your Build/ and Builds/ output, and the *.csproj and *.sln files Unity regenerates for your code editor. Those are the key lines of the tool’s Unity template, which has 34.

What the blocks ignore

  • Editor caches: /Library/, the import cache, which can grow to gigabytes; /Temp/, /Obj/, /Logs/, /MemoryCaptures/ and /Recordings/.
  • Per-user settings: /UserSettings/, your editor layout and preferences.
  • Builds: /Build/, /Builds/, *.apk, *.aab, *.app and exported *.unitypackage files.
  • IDE files: *.csproj, *.sln, .vs/, *.user, debug symbols such as *.pdb, and the .meta files Unity writes for those.

In a scratch repository with this file, git check-ignore -v -n --no-index names the line that matched each path, or prints :: when none did:

.gitignore:3:/Library/	Library/ArtifactDB
.gitignore:10:/UserSettings/	UserSettings/EditorUserSettings.asset
::	Assets/Scripts/Player.cs.meta
::	Assets/Editor/Build/BuildScript.cs
::	ProjectSettings/ProjectSettings.asset
::	Packages/packages-lock.json
.gitignore:17:*.csproj	Assembly-CSharp.csproj
.gitignore:7:/Builds/	Builds/Windows/MyGame.exe

Commit every .meta file

Each .meta file holds its asset’s GUID, and scenes and prefabs refer to assets by that GUID. Lose one and every reference to the asset breaks. Commit Assets/ with all its .meta files, ProjectSettings/, and Packages/manifest.json with packages-lock.json. The leading slashes are why Assets/Editor/Build/ of your own stays tracked.

The file must sit next to Assets/

A leading slash anchors a line to the folder its .gitignore is in. If the Unity project lives in Game/ inside the repository, a root file misses its cache entirely:

::	Game/Library/ArtifactDB

Put the same file in Game/ and Git reports it from there:

Game/.gitignore:3:/Library/	Game/Library/ArtifactDB

Keeping a package you depend on

*.unitypackage also catches a third-party package you mean to commit. A later ! line brings it back, because its folder isn’t excluded:

.gitignore:44:!Assets/ThirdParty/*.unitypackage	Assets/ThirdParty/Tween.unitypackage
.gitignore:39:*.unitypackage	Exports/MyKit.unitypackage

Nothing inside /Library/ can be re-included that way: Git never looks into an excluded directory.

Committed Library/ already?

.gitignore only affects untracked files. Untrack the caches, keeping them on disk, and commit:

git rm -r --cached Library Temp Obj Logs UserSettings
git commit -m "Stop tracking Unity caches"

Editor and OS files

.idea/ from Rider, .vscode/ and .DS_Store come from your machine. Keep them in a global ignore file:

git config --global core.excludesFile ~/.gitignore_global

Try it in the Gitignore Generator

In the file: Unity

.gitignore

1 template · 34 pattern lines
# Unity
# Folders Unity writes at the project root, anchored so an Assets/Editor/Build/ of your own stays
/Library/
/Temp/
/Obj/
/Build/
/Builds/
/Logs/
# Per-user editor layout and preferences
/UserSettings/
/MemoryCaptures/
/Recordings/
.vs/
.gradle/
/ExportedObj/
# Generated whenever Unity regenerates the solution
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
# Meta files Unity writes for the generated files above
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Written next to a crash report
sysinfo.txt
*.apk
*.aab
# Packages exported for the Asset Store
*.unitypackage
*.app
crashlytics-build.properties
  • ✓Not ignored: no line in this file matches "/Assets/Scripts/Player.cs.meta".

Lines are applied top to bottom, and the last one that matches wins — which is why a line of your own can overrule a template.

Runs in your browser. Nothing you enter is sent anywhere.