Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Github wants to upload everyhing!

Discussion in 'Getting Started' started by MikeTeavee, Mar 14, 2016.

  1. MikeTeavee

    MikeTeavee

    Joined:
    May 22, 2015
    Posts:
    194
    "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.
     
    Last edited: Mar 14, 2016
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,509
    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.
     
  3. MikeTeavee

    MikeTeavee

    Joined:
    May 22, 2015
    Posts:
    194
    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...?

    Code (.gitignore):
    1.  /[Ll]ibrary/
    2. /[Tt]emp/
    3. /[Oo]bj/
    4. /[Bb]uild/
    5. /[Bb]uilds/
    6. /Assets/AssetStoreTools*
    7.  
    8. # Autogenerated VS/MD solution and project files
    9. ExportedObj/
    10. *.csproj
    11. *.unityproj
    12. *.sln
    13. *.suo
    14. *.tmp
    15. *.user
    16. *.userprefs
    17. *.pidb
    18. *.booproj
    19. *.svd
    20.  
    21.  
    22. # Unity3D generated meta files
    23. *.pidb.meta
    24.  
    25. # Unity3D Generated File On Crash Reports
    26. sysinfo.txt
    27.  
     
  4. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,509
    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.
     
    MikeTeavee likes this.
  5. MikeTeavee

    MikeTeavee

    Joined:
    May 22, 2015
    Posts:
    194
    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?
     
  6. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,509
    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.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    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.
     
    jhocking and MikeTeavee like this.
  8. MikeTeavee

    MikeTeavee

    Joined:
    May 22, 2015
    Posts:
    194
    Oh that's great, thanks BoredMormon! I'm definitely gonna try to open that.

    Ah I see now... great, thank you!
     
  9. maquis

    maquis

    Joined:
    Feb 7, 2016
    Posts:
    61
    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. :)
     
  10. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,509
    The meta files are there specifically for your versioning software! So yes, make sure they're there.

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

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    .meta files contain all of your serialised inspector data. So your project will fall apart without them.
     
    jhocking and Schneider21 like this.
  12. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,509
    I knew they were important. I just didn't know exactly what they did. Thanks for the save!
     
  13. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    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.
     
  14. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    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"...
     
    Ryiah likes this.
  15. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,322
    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! :)
     
  16. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    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.
     
  17. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,322
  18. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    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.
     
  19. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Here is one of mine. It's a pretty standard .gitignore downloaded from the net.

    https://bitbucket.org/BoredMormon/t...ignore?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.
     
    Schneider21, APSchmidt and Ryiah like this.
  20. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    812
    You need the Assets and ProjectSettings folders, ignore everything else. Unity generates all that other stuff automatically.
     
  21. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    A follow-up warning... this VS ignore file includes *.meta, some weirdness related to .NET Core.

    Unity requires *.meta files so remove that entry if you mix this into a Unity gitignore file.