Unity and Git/GitHub not playing nice

I know things like this have been asked before. I’ve read through a dozen threads between here and StackOverflow and I haven’t found a solution that works for my situation. Apologies ahead of time for possibly beating a dead horse some more.

The short of it is that my gitignore doesn’t seem to work. I’ll post my current gitignores at the bottom. I have tried many other versions. I added a little bit to the gitignore in the problem project to test.

I’m working through an Udemy course for Unity and C# and I’m trying to use GitHub for version control because I’m playing with things beyond what the course is doing. I have multiple projects in my repo because the course covers different types of games. I have tried placing the gitignore in the root of the repo outside of individual projects, and I have tried placing copies inside of individual projects root folders.

It wasn’t a problem with the first two projects but the third, Coyote McRain, uses asset packs from the Unity Asset Store. As soon as I painted some asset pack textures to my terrain I couldn’t push to GitHub anymore and I started digging to find the problem. No gitignore version that I’ve tried has stopped Library or other folders/files from being committed.

I have made sure that Asset Serialization Mode is Force Text and Version Control is Visible Meta Files in Unity. I tried creating a new repo to start fresh and just copy pasta the individual project folders over. Still doesn’t work. I’m completely lost here.

Just in case it helps I’ll put my repo links.
Original: GitHub - RustyDeGarmo/Udemy-Csharp-Unity-Game-Development: Udemy course for learning game development with C# and Unity
Test: https://github.com/RustyDeGarmo/UnityTest

gitignore used in most places:

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

Get latest from gitignore/Unity.gitignore at main · github/gitignore · GitHub

**/[Ll]ibrary/
**/

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

gitignore used in Starship Coyote project root is basically the same but I added the following to the bottom:

/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

The gitignore filename must be .gitignore but the one in the repo is named .gitignore.txt

1 Like

Thank you! This was a hard way to learn this lesson but I probably won’t forget that again so it’s good.

Sounds like you’re good now but just for completeness sake, here’s my notes.

PROPERLY CONFIGURING AND USING ENTERPRISE SOURCE CONTROL

I’m sorry you’ve had this issue. Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

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:

I usually make a separate repository for each game, but I have some repositories with a bunch of smaller test games.

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

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

Share/Sharing source code between projects:

Setting up an appropriate .gitignore file for Unity3D:

Generally the ONLY folders you should ever source control are:

Assets/
ProjectSettings/
Packages/

NEVER source control Library/ or Temp/ or Logs/
NEVER source control anything from Visual Studio (.vs, .csproj, none of that noise)

Setting git up with Unity (includes above .gitignore concepts):

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. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It’s simply ridiculous not to back up.

If you plan on joining the software industry, you will be required and expected to know how to use source control.

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