Skip to content

Instantly share code, notes, and snippets.

@FullStackForger
Last active April 6, 2024 13:19
Show Gist options
  • Save FullStackForger/20bbf62861394b1a3de0 to your computer and use it in GitHub Desktop.
Save FullStackForger/20bbf62861394b1a3de0 to your computer and use it in GitHub Desktop.
.gitignore for Unity3d project
###
# Unity folders and files
###
[Aa]ssets/AssetStoreTools*
[Bb]uild/
[Ll]ibrary/
[Ll]ocal[Cc]ache/
[Oo]bj/
[Tt]emp/
[Uu]nityGenerated/
# file on crash reports
sysinfo.txt
# Unity3D generated meta files
*.pidb.meta
###
# VS/MD solution and project files
###
[Ee]xportedObj/
*.booproj
*.csproj
*.sln
*.suo
*.svd
*.unityproj
*.user
*.userprefs
*.pidb
.DS_Store
###
# OS generated
###
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
@FullStackForger
Copy link
Author

Good response on stackoverflow http://stackoverflow.com/a/18225479

@unrelentingfox
Copy link

unrelentingfox commented Jan 18, 2018

You have "*.pidb.meta" but I don't think that matches any files in my unity project. Shouldn't it just be "*.meta" or should I actually commit some meta files?

@SteveDAC
Copy link

Shouldn't it just be "*.meta" or should I actually commit some meta files?

You absolutely do need to commit .meta files!

@johnnathanmak
Copy link

Newbie here, will this work for collaboration between mac and PC?

@kafoso
Copy link

kafoso commented Dec 27, 2018

As mentioned in this comment: https://www.youtube.com/watch?v=qpXxcvS-g3g&lc=UgymTHStHTb7DKyayRR4AaABAg

You probably want to revise the .gitignore change. The removal of the starting slash will match any folder with those names absolutely anywhere, and that is not what you want. So either (A) "/*/[Ll]ibrary/" or - for this specific case and more accurately in general - (B) use "/Example Game Project/[Ll]ibrary/", where "Example Game Project" is of course replaced by the name of the folder, you are using. Additionally, I'll recommend always naming this very folder simply "Unity". The repository name and README.md file should contain the necessary information for your project. This also means you can largely copy the same .gitignore between different Unity projects.

I.e.:

  1. Rename folder "Example Game Project" to "Unity" (mv Example\ Game\ Project Unity).
  2. Change corresponding lines in .gitignore to:
/Unity/[Aa]ssets/AssetStoreTools*
/Unity/[Bb]uild/
/Unity/[Ll]ibrary/
/Unity/[Ll]ocal[Cc]ache/
/Unity/[Oo]bj/
/Unity/[Tt]emp/
/Unity/[Uu]nityGenerated/

@theTcube
Copy link

theTcube commented Feb 1, 2019

Should we commit all the meta files along with other stuffs or should we just skip them?

@leve1997
Copy link

leve1997 commented Mar 5, 2019

Can you use the same file for 2d projects?

@Suyashtnt
Copy link

Can you use the same file for 2d projects?

yes you can

@Kenshokram
Copy link

If you rename the folder to Unity, that project in the unity hub will then be called "Unity", which isn't great. Is there a way to go around this or is the best solution to just write the name of the project in the ignore on every new project?

@FullStackForger
Copy link
Author

RE: on meta files. *.meta files are committed. we are only ignoring *.pidb.meta.

@YahyaHammad
Copy link

does this work with mac or is it windows only (it looks like windows only)

@Vire7777
Copy link

Why the "Icon ?" is important ?
I mean it makes a lot of mistakes to me as many folders in many packages are called Icons
Because of that it ignores all these folders

@yankikucuk
Copy link

Why the "Icon ?" is important ?
I mean it makes a lot of mistakes to me as many folders in many packages are called Icons
Because of that it ignores all these folders

"Icon?" is MacOS only. Like ".DS_Store" and ".DS_Store?". You can remove these lines if you working on only PC platform(s).

@FullStackForger
Copy link
Author

Missed the above comment, but yeah, I am using both Win and Mac so Icon was needed. Just remove whatever you don't need.

@FakeMG
Copy link

FakeMG commented Aug 1, 2021

Why don't we just commit the whole project? I'm a newbie

@Akselmo
Copy link

Akselmo commented Aug 2, 2021

Why don't we just commit the whole project? I'm a newbie

Some of the files are unnecessary data that will get built by Unity anyway when importing the project. There are files that can get really big, from hundreds to thousands of megabytes, like baked lightmapping data, so that shouldn't be uploaded to Git (Git doesn't handle large files that well, although Git Large File Support can help with that).

Git is made mainly for comparing code and text. In game projects though, I usually upload the following: Code, textures, models, sound, scene files and so on. The .meta files help Unity to figure out when importing, what settings does specific thing have, without having to import the actual data. Like, let's say this one scene has huge lightmap. Metadata has "this scene has lightmap, let's build one since we can't find one."

So to summarize, some files are way too large to handle in Git.

Hope this helps!

@dimitradg
Copy link

Hey there! I am also trying to upload a Unity project on GitHub, so I want to use .gitignore in order to upload only the necessary files.

However, .gitignore doesn't seem to work.

I have tried:
a) removing the slashes in front of the folders, like this .gitignore file recommends
b)using the project's folder name before the folders, e.g.:
/Unity/[Uu]nityGenerated/

Both .gitignore file and Unity Project are inside my GitHub's repository folder.

Any held would be much appreciated.

Thank you in advance!

@Akselmo
Copy link

Akselmo commented Oct 7, 2021

You may have to add the same .gitignore file inside the unity project folder. I remember one case where I had to do that. Other than that, I can't think of anything. Hope that helps.

@FullStackForger
Copy link
Author

Hey there! I am also trying to upload a Unity project on GitHub, so I want to use .gitignore in order to upload only the necessary files.
However, .gitignore doesn't seem to work.

I don't fully understand what it is that you trying to do but it seems to me, you are not using git correctly. I would recommend practicing simple git setup without unity first so you get a grip on basics. Have a look at tutorials, like Git basiscs by Atlassian or Git Docs.

.gitignore` is a git specific file, it should be placed at the top level in each repository folder created individual for every unity project. Pasted file doesn't require any edits.

@dimitradg
Copy link

Hello!

Thank you for your answers!

Taking under consideration your insights, and after doing some research, what did work for me is that I imported git for unity, which automatically creates a local repository with the necessary .gitignore file, and that worked properly.

Thank you for you time :)

@omri-mizrahi
Copy link

omri-mizrahi commented Apr 22, 2022

  1. Why do we commit the Logs folder?
  2. I added in my gitignore the following line in order to avoid uploding anything regarding the webgl build, is that ok?
    *webgl*

@FullStackForger
Copy link
Author

  1. Good point with Logs @kuskus110 (updating now)
  2. I would build webgl into a build folder (which is already ignored)

@omri-mizrahi
Copy link

omri-mizrahi commented Apr 29, 2022 via email

@Ivano-P
Copy link

Ivano-P commented Jul 27, 2022

Hello, is this .gitignore still up to date or have you made any changes to the one you use now?
thank you, this already helped allot.

@FullStackForger
Copy link
Author

Totally missed your message @Ivano-P. I think the best way is to start new github project with Unity .gitignore and possibly add OS related section if you want to.

@Ivano-P
Copy link

Ivano-P commented Nov 23, 2022

@FullStackForger thanks, That's what I did.

@FullStackForger
Copy link
Author

@Ivano-P Not sure if that will apply for you but I have started to ignore /UserSettings folder, mainly because wouldn't want to enforce my settings on others and vice-versa.

@Ivano-P
Copy link

Ivano-P commented Nov 29, 2022

Oh yes, I will probably do that when I finish my test version and decide to work with a 3d artist, but in my case I use it to switch to my laptop when I'm on the move so having the same settings if what I want.

@ralphmettle
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment