When I created a git repo (on github) for my unity game, GitHub offered me a template .gitignore file which I assumed would prevent files that I don’t need to backup from being saved in the repo.
However, even though I may just open the project, make a few changes to a few c# files and play the game… tons of files are flagged by git as modified…
Do I need to add more stuff to my gitignore file? Below is an example of all the changed files when I just edited 3 c# files (I assume I can get rid of the log files, not sure about the rest)
# 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
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[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
*.unitypackage
# Crashlytics generated file
crashlytics-build.properties
The default file should be enough.
Make sure it’s at the root of your project directory - it looks like it isn’t finding your Library folder to exclude.
changing /[Ll]ibrary/ to **/[Ll]ibrary/ will fix the issue. also works for nested subfolders (meaning if you have multiple unity projects in one repository and place .gitignore in the root folder of the repo)
I did this, and it ignores 8000+ files I untracked with git rm -r --cached, but it still tracks files like Library/ArtifactDB and Library/PackageManager/ProjectCache. Is there a solution to make it ignore those files?
@Jeper : Using /[Ll]ibrary/ will exclude everything in the Library folder, including subdirectories. But this also assumes your gitignore will be at the root of your project (in the same folder as your csproj files, the Assets, Library, Packages folders, etc) and that the git repo is at the project root as well.
I’ve used the standard Unity gitignore for years and have never had an issue with stuff being included that shouldn’t be.
I think you are creating your Unity project in a subfolder of the repo root. In that case, one of these should solve the problem:
Append the folder name to the anchored folders in your gitignore: /MyUnityProject/[Ll]ibrary/ instead of /[Ll]ibrary/.
Move the gitignore to the folder that contains the unity project. You may need another gitignore at the root depending on your setup.
I do not recommend adding double asterisks at the beginning of the patterns (**/[Ll]ibrary/) as it will ignore any folder named Library or library anywhere in the project.
Hello. The default gitignore isn’t working for me either. I know for a fact it is in my root folder and SourceTree is still reading every single file in the Unity folder. I’m using the most up to date Unity version and have Visible Meta Files, Force Text selected. I also tried the first method suggested by @starikcetin and no luck. Is there something I’m missing?
Wait, I’m confused. So I have to type in the terminal every single time I and the team commits? Is it a directory that I can reference or do I have to type in every single file I want to ignore? That’s…a lot of files.
Also, git rm --rf --cached didn’t work. It gave me an error. I’m using Source Tree and Terminal is Git Bash.