Github wants to upload everyhing!

“Za goggles, zay do nothing!” …and by goggles I mean Googles.

Bad jokes aside, I’m really struggling with GitHub, and I would also love to know the correct use in a Unity environment.

For the record I’m using my wifes MacBook and therefore Github will be useful as I need to get all my script files to my desktop. Yes I could email the files over or use dropbox, but I’ve been delaying the use of Github too long now, it’s time to learn!

Ideally, I would love to put the entire project on GitHub if possible, but I have these 3D model assets that I purchased from the Asset Store, and I’m pretty sure it would be illegal to host them publically on GitHub. I’m really not sure how to proceed at this point. Am I even supposed to upload scene files, prefabs and all that stuff?

Here are the steps I’ve taken so far…

  1. I created a repository on the website (let’s call it “MyRepo”) and added the standard Github Unity gitignore file.

  2. In GitHub Desktop, I cloned the repo into a local folder “MyRepo” which has the same gitignore file

  3. In Unity, I setup ProjectSettings>Editor with “Visible Meta Files” and also Asset Serialization to “Force Text”

  4. I cut and paste all the files of my project into the newly created MyRepo folder, (this is the project folder I will be working in now.)

  5. I went into Github and I saw 762 files waiting to be committed. About 1.5Gb.

I guess I could upload everything, but theres a legality aspect, as well as a long wait as my upload speed is not great.

I could also just check off all the files and just commit & push the script files I have… but then what the heck is the gitignore file for? I though it hid everything but the script files, GitHub is for code right?

So confused, if anyone could help me, I would be more than appreciative. Maybe you could tell me what types of file you upload, and don’t upload.

First of all, if you’re not already using a .gitignore file, do so. This will keep you from uploading unnecessary files like .csproj and your Build directory. Here’s a good starting gitignore one for Unity projects.

While Git is mainly for code and versioning changes, it can handle storing binary data as well, like images and models. It doesn’t version between these files, though, so if you make a change to an image or model, the entire thing gets a new reference created. The consequence of this is that if you are making frequent changes to binary-type files and regularly commit them to the repo, your repo’s size is going to blow up pretty quickly.

Some people prefer to maintain their models and images and such outside of Git. I never bothered to do that. I’m just generally careful with what I commit (only the actual used asset, not the originals like .psd or .blend files). This way I can go to a new computer, pull down my repo and have a fully-functioning instance of the project to work from without having to download extra files from elsewhere.

Next, I don’t use GitHub for Unity projects simply because of the open requirement. BitBucket has all the same functionality, but with unlimited private repos. Only downside I’ve run into so far is that repos are soft-capped at 1GB and hard-capped at 2GB. When I was being careless about my commits and binary inclusions, I hit the soft cap, but finished before running into the hard cap.

5 Likes

The gitignore is there, I should have read the gitignore file first before posting. Looking at this, I think it makes sense. It blocks out all the stuff you don’t need to copy over to get it working on another machine…?

 /[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*

# Autogenerated VS/MD solution and project files
ExportedObj/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd


# Unity3D generated meta files
*.pidb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

Right. Generally, you want to include everything in the Assets directory, and nothing else. Obviously you don’t want to include builds, as your repo will quickly become larger than my… well, let’s just say it’ll be big. Likewise, since the .sln, .unityproj, etc. files are generated by Unity, you don’t need those, and including them will just bloat your repo. Even worse, if things get generated differently on another machine, you may actually get merge conflicts you’d need to resolve.

1 Like

Thank you Schneider, this is all very helpful. So you’re telling me, if I wanted to, I could theoretically visit your GitHub, clone a repository to a local folder, and that project would open right up in Unity?

You could if I put it on GitHub. But since I use BitBucket, I’d have to invite you to share my repo first. But yes, that’s the idea. And I know it works because I’ve transferred projects to other computers using this method.

Yes.

You can practice on one of my bitbucket projects if you like. Here is a small one that should open up directly. https://bitbucket.org/BoredMormon/trend.me

I’d also second using bitbucket over github. Being able to make your own private repos is incredibly useful.

2 Likes

Oh that’s great, thanks BoredMormon! I’m definitely gonna try to open that.

Ah I see now… great, thank you!

Do any of the *.meta files need to be stored? It looks like thd .gitignore will include some of them in the repo, but im guessing that they shouldnt be necessary.

So far, I am using a home server for managing my git repos, ans looking at using s3 for an emergency backup. :slight_smile:

The meta files are there specifically for your versioning software! So yes, make sure they’re there.

http://docs.unity3d.com/Manual/ExternalVersionControlSystemSupport.html

.meta files contain all of your serialised inspector data. So your project will fall apart without them.

2 Likes

I knew they were important. I just didn’t know exactly what they did. Thanks for the save!

Turn on text serialisation and read a few one day. It’s quite useful. And with version control it lets you see exactly what you have changed.

Butting into an old thread here… I’d also suggest adding the Visual Studio entries to that Unity gitignore. The Unity one seems to assume you’re only deploying to Android (apk is the only binary).

https://www.gitignore.io/api/visualstudio

Our setup at home is to put the “bare” repo on our NAS (think of it as the centralized, shared repo, same as the copy you’d have up on GitHub or some other server), and of course, that NAS is backed up every night by another NAS. I mention the bare repo because I’ve seen a lot of discussion online of confusion about the relationship between “git init” and “git init --bare”…

1 Like

I’m using BitBucket to save my projects. So far, I committed everything in the project directory since I wasn’t sure what was useful to commit or not, so, I take the opportunity to ask, what in a project must we commit to BitBucket? A project contains:

  • Assets
  • Library
  • obj
  • ProjectSettings

and a host of individual files, csproj, unityproj, sln and userprefs.

Can I use your “gitignore” file as it is in your project?

Thanks for your answer! :slight_smile:

Sure would be nice if somebody from Unity would whip up a good, safe .gitignore for us…

Oh, for anybody running 5.5.0f3 – upgrade to 5.5.0p1 to avoid this bug.

There is a beginning of an answer here: Unity Cloud Build - Unity Learn, scroll down to chapter 6. but it’s still a bit vague as to what we can ignore or not.

Another gotcha to look out for: VS2015’s git support will recognize you’ve set up a working copy and will let you check-in code changes right from the IDE, and can even push to the centralized bare repository. However, it will not touch anything outside of Visual Studio such as scene files or asset information…

The git command line is actually pretty simple, but we use SourceTree, if anybody is looking for a recommendation. It’s free and multi-platform.

Here is one of mine. It’s a pretty standard .gitignore downloaded from the net.

https://bitbucket.org/BoredMormon/trend.me/src/bd10b392daa8a35ce720960c21a0ac2457698d29/.gitignore?at=master&fileviewer=file-view-default

In practice you only need the Assets folder and the project settings folder. You should ignore any build folders, as this will bloat your repo without any gain.

You should also ignore the library folder. This contains computer specific optimisations. And it actually tends to break the project if it’s shared.

3 Likes

You need the Assets and ProjectSettings folders, ignore everything else. Unity generates all that other stuff automatically.

4 Likes