├── testproject.jpg ├── NYU_GameCenter_Logo_Formatted_Thin.png ├── .gitconfig ├── post-merge ├── .gitignore ├── pre-commit ├── .gitattributes └── README.md /testproject.jpg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8ba706215be4b4a18ec94b5eba34a98d4978001331c25ff62753fd3755bd69c7 3 | size 102541 4 | -------------------------------------------------------------------------------- /NYU_GameCenter_Logo_Formatted_Thin.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:6b6fbebc08e857907bf7caad3fbd85d515d124a19e3bb8ddd517c1931875ba87 3 | size 37287 4 | -------------------------------------------------------------------------------- /.gitconfig: -------------------------------------------------------------------------------- 1 | [merge] 2 | tool = unityyamlmerge 3 | 4 | [mergetool "unityyamlmerge"] 5 | trustExitCode = false 6 | cmd = '' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED" 7 | -------------------------------------------------------------------------------- /post-merge: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Post-merge hook to ensure that empty folders get deleted 4 | # This file is based on https://github.com/strich/git-dir-cleaner-for-unity3d/ 5 | # 6 | # After cloning your repo, put this file into directory /.git/hooks. To disable it remove it from there. 7 | 8 | # Command line options: 9 | isSquashMerge="$1" 10 | 11 | dirsRemovedCounter=0 12 | 13 | echo "Removing empty directories..." 14 | 15 | # Grab a list of deleted files: 16 | changedFiles="$(git diff-tree -r --name-only --diff-filter=D --no-commit-id ORIG_HEAD HEAD)" 17 | 18 | # Early exit if there are no removed files at all: 19 | if [ -z "$changedFiles" ]; then 20 | exit 0 21 | fi 22 | 23 | # Get the list of dir paths and then sort and remove dupes: 24 | dirsToCheck="$(echo "$changedFiles" | xargs -d '\n' dirname | sort -u)" 25 | 26 | # For each dir check if its empty and if so, remove it: 27 | for dir in $dirsToCheck; do 28 | if [ ! -d "$dir" ]; then 29 | continue 30 | fi 31 | 32 | ((dirsRemovedCounter++)) 33 | 34 | find "$dir" -type d -empty -delete 35 | done 36 | 37 | echo "Removed" $dirsRemovedCounter "directories." 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore git config as it will be differ across clients 2 | .gitconfig 3 | 4 | # unity generated folders 5 | library/ 6 | temp/ 7 | obj/ 8 | build/ 9 | builds/ 10 | logs/ 11 | bin/ 12 | Library/ 13 | Temp/ 14 | Obj/ 15 | Build/ 16 | Builds/ 17 | Logs/ 18 | Bin/ 19 | 20 | # erroneous meta files 21 | library.meta 22 | temp.meta 23 | obj.meta 24 | build.meta 25 | builds.meta 26 | logs.meta 27 | bin.meta 28 | Library.meta 29 | Temp.meta 30 | Obj.meta 31 | Build.meta 32 | Builds.meta 33 | Logs.meta 34 | Bin.meta 35 | 36 | 37 | # Never ignore Asset meta data 38 | ![Aa]ssets/**/*.meta 39 | 40 | # Ignore Jetbrains Plugin 41 | Assets/Plugins/Editor/JetBrains.meta 42 | Assets/Plugins/Editor/JetBrains/* 43 | JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta 44 | assets/Plugins/Editor/JetBrains.meta 45 | assets/Plugins/Editor/JetBrains/* 46 | 47 | # comment these out if you wish to commit the asset store tools plugins 48 | assets/AssetStoreTools* 49 | Assets/AssetStoreTools* 50 | AssetStoreTools.meta 51 | 52 | # Visual Studio cache directory 53 | .vs/ 54 | 55 | # Rider 56 | **/.idea/** 57 | .idea/** 58 | 59 | #maya intermediate files 60 | **/incrementalSave/ 61 | 62 | # wwise intermediate files 63 | **/.cache/ 64 | *.akd 65 | 66 | # fmod autogen files 67 | fmod.log 68 | fmod_editor.log 69 | **/FMODStudioCache.asset 70 | **/FMODStudioCache.asset.meta 71 | **/FMODStudioSettings.asset 72 | **/FMODStudioSettings.asset.meta 73 | **/.cache/* 74 | **/.restore/* 75 | **/.user/* 76 | 77 | # Gradle cache directory 78 | .gradle/ 79 | 80 | # Autogenerated VS MD Consulo solution and project files 81 | ExportedObj/ 82 | .consulo/ 83 | *.csproj 84 | *.unityproj 85 | *.sln 86 | *.suo 87 | *.tmp 88 | *.user 89 | *.userprefs 90 | *.pidb 91 | *.booproj 92 | *.svd 93 | *.pdb 94 | *.mdb 95 | *.opendb 96 | *.VC.db 97 | *Resharper* 98 | *ReSharper* 99 | *.orig 100 | *.orig.* 101 | 102 | # Unity3D generated meta files 103 | *.pidb.meta 104 | *.pdb.meta 105 | *.mdb.meta 106 | 107 | # Unity3D generated file on crash reports 108 | sysinfo.txt 109 | 110 | # Builds 111 | *.apk 112 | *.apk.meta 113 | *.unitypackage 114 | *.unitypackage.meta 115 | 116 | # Crashlytics generated file 117 | crashlytics-build.properties 118 | 119 | # Audio waveform preview files 120 | *.reapeaks 121 | *.reapeaks.meta 122 | *.pk 123 | *.pk.meta 124 | *.pkf 125 | *.pkf.meta 126 | *.asd 127 | *.asd.meta 128 | 129 | # OS generated 130 | .DS_Store 131 | .DS_Store? 132 | ._* 133 | .Spotlight-V100 134 | .Trashes 135 | Icon? 136 | Thumbs.db 137 | Desktop.ini 138 | ehthumbs.db 139 | Local/* 140 | -------------------------------------------------------------------------------- /pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Pre-commit hook script for Unity to ensure meta files stay in sync, as well as check that every folder & file 4 | # marked to be ignored in .gitignore has an entry for its meta file to be ignored too. 5 | # Based on this: https://github.com/kayy/git-pre-commit-hook-unity-assets & https://github.com/doitian/unity-git-hooks 6 | # 7 | # 8 | # After cloning your repo, put this file into directory /.git/hooks. To disable it remove it from there. 9 | 10 | ASSETS_DIR="$(git config --get unity3d.assets-dir || echo "Assets")" 11 | 12 | if git rev-parse --verify HEAD >/dev/null 2>&1 13 | then 14 | against=HEAD 15 | else 16 | # Initial commit: diff against an empty tree object 17 | against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 18 | fi 19 | 20 | # Redirect output to stderr. 21 | exec 1>&2 22 | 23 | # ensure that there's not a >100mb file in this checkin, which github won't allow 24 | CURRENT_DIR="$(pwd)" 25 | HAS_ERROR="" 26 | COMMIT_TEXT=$(git diff --cached --name-only | sort | uniq) 27 | SAVEIFS=$IFS 28 | 29 | IFS=" 30 | " 31 | for file in $COMMIT_TEXT; do 32 | file_size=$(du -m $CURRENT_DIR/$file | awk '{print $1}') 33 | if [ "$file_size" -ge 100 ]; then 34 | echo "$file is over 100MB." 35 | HAS_ERROR="1" 36 | fi 37 | done 38 | IFS=$SAVEIFS 39 | 40 | if [ "$HAS_ERROR" != "" ]; then 41 | echo "Can't commit, fix errors first." >&2 42 | exit 1 43 | fi 44 | 45 | git diff --cached --name-only --diff-filter=A -z $against -- "$ASSETS_DIR" | while read -d $'\0' f; do 46 | ext="${f##*.}" 47 | base="${f%.*}" 48 | 49 | if [ "$ext" = "meta" ]; then 50 | if [ $(git ls-files --cached -- "$base" | wc -l) = 0 ]; then 51 | cat < 2 | 3 | # Unity Github Config 4 | - [Git Primer](#git-primer) 5 | - [Setup Instructions](#setup-instructions) 6 | - [Usage and Errors](#usage-and-errors) 7 | - [Troubleshooting](#troubleshooting) 8 | - [Additional Information](#additional-information) 9 | 10 | We've put together some git configuration files to cover the majority of Unity/Git use cases. If you set these up at the start, they should prevent your repos from filling up with cruft. These config files ensure that all large files are tracked by git lfs & that your changes are diff'd appropriately, while the pre-commit/post-merge hooks ensure that meta files stay properly in sync. They also insure you against accidentally trying to upload a >100mb file to github, and ending up with a sad unresolvable local repo. 11 | 12 | This process has 4 phases & some prequisites. Please make sure to complete all phases before starting work on your project. 13 | 14 | 0. [Prerequisites](#prerequisites) 15 | 1. [Configure Unity for Git](#configure-unity-for-git) 16 | 2. [Create and Configure Your Repo](#create-and-configure-your-repo) 17 | 3. [Install GitLFS](#install-gitlfs) 18 | 4. [Invite Teammates](#invite-teammates) 19 | 20 | # Git Primer 21 | 22 | Want a primer on git? 23 | 24 | * [Git, the simple guide](http://rogerdudler.github.io/git-guide/) - A very simple primer 25 | * [Git Magic](http://www-cs-students.stanford.edu/~blynn/gitmagic/) - A command-oriented, more extensive git primer 26 | * [Git on the Command Line](https://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html) - a command line git primer 27 | * [Swarthmore Git Intro](https://www.cs.swarthmore.edu/help/git/) - A more conceptually-driven git primer 28 | 29 | How about a cheatsheet? 30 | 31 | * [Rogerdudler's Cheatsheet](https://rogerdudler.github.io/git-guide/files/git_cheat_sheet.pdf) - Just the essentials, one-pager 32 | * [GitHub's Cheatsheet](https://services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf) - More extensive, longer descriptions 33 | * [NDP's Cheatsheet](http://www.ndpsoftware.com/git-cheatsheet.html) - Interactive, even more extensive 34 | 35 | # Setup Instructions 36 | 37 | ## Prerequisites 38 | 39 | Unity 2017 or newer. Tested up to Unity 2018.3. 40 | 41 | * Mac: Git installed either through Xcode command line tools, or from here: http://git-scm.com/download/mac 42 | * Windows: Git installed using GitForWindows: https://gitforwindows.org/ Note that other windows git installs that don't include gitbash will cause the pre-commit & post-merge hooks to fail, negating many of the key benefits of this setup. 43 | 44 | 45 | ## Configure Unity for Git 46 | 47 | 1. Create a new unity project. 48 | 49 | 2. Open the editor settings: 50 | 51 | `Edit > Project Settings > Editor` 52 | 53 | 3. Force visible .meta files (this will ensure script execution order & object references are maintained) 54 | 55 | `Version Control / Mode: “Visible Meta Files”` 56 | 57 | 4. Force text serialization (this will ensure you can merge & properly diff your assets) 58 | 59 | `Asset Serialization / Mode: “Force Text”` 60 | 61 | 5. Save changes 62 | 63 | `File > Save Project` 64 | 65 | ## Create and Configure Your Repo 66 | 67 | 1. Create a new github repo with the same name as your Unity project. Don't select the default Unity .gitignore, we'll be importing our own later. 68 | 69 | 2. Clone the repo to the Unity project folder you created in "Configure Unity for Git". 70 | 71 | >If you can't see the `/.git/` folder, make it visible by following [these steps for Windows](https://kb.wisc.edu/page.php?id=27479) or [these steps for Mac](https://ianlunn.co.uk/articles/quickly-showhide-hidden-files-mac-os-x-mavericks/). 72 | 73 | 3. Download the .gitconfig, .gitignore, and .gitattributes file from this into the root of the local repo you just cloned, ie into the folder `/`. 74 | 75 | 4. Edit .gitconfig with a text editor, replacing `` with the location of your Unity install's merge tool (note that these locations can vary if you picked a different install folder during unity install. Also note that you will need to edit this file again if you upgrade Unity & choose a different install location.) 76 | >On Windows it's usually: `C:\\Program Files\\Unity\\Editor\\Data\\Tools\\UnityYAMLMerge.exe` or `C:\\Program Files (x86)\\Unity\\Editor\\Data\\Tools\\UnityYAMLMerge.exe` (double slashes are necessary as escape characters). 77 | 78 | >On Mac it's usually: `/Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge`. 79 | 80 | This merge tool will try to merge or resolve conflicts within .prefab, .scene, and other unity asset files. If it can't do it automatically, your default merge tool will open & you can manually select which changes to include. 81 | **Always open any merged unity assets & confirm the merge worked before pushing the merged assets.** For more info, check [this git hub post](https://github.com/anacat/unity-mergetool) or [this blog post](http://www.jameskeats.com/blogs/post/Unitys-SmartMerge-Meets-SourceTree/). 82 | 83 | 5. Copy the contents of your Unity project into the new folder. 84 | 85 | 6. Commit these changes to your new repo & push. Your new project should look like this on Github: 86 | 87 |
88 | (Keep scrolling, you're not done yet!) 89 | 90 | ## Install GitLFS 91 | 92 | 1. Download & install git-lfs from https://git-lfs.github.com/. If you've already installed git-lfs, proceed to step 2. 93 | 94 | 2. Open a command prompt, terminal, or gitbash window. 95 | 96 | 3. Navigate to the folder containing your git repository & execute: `git lfs install` 97 | 98 | 4. That's all you need to do, as tracking the appropriate files in lfs is taken care of by the .gitattributes file. If you're already familiar with git, you might consider reading [this intro to git-lfs](https://github.com/git-lfs/git-lfs/wiki/Tutorial), as working with it varies from vanilla git quite a bit. 99 | 100 | 5. Download the [pre-commit](https://github.com/NYUGameCenter/Unity-Git-Config/blob/master/pre-commit) & [post-merge](https://github.com/NYUGameCenter/Unity-Git-Config/blob/master/post-merge) scripts. Enable them in your repo by moving them into the folder `/.git/hooks/`. These will ensure that meta files stay in sync. It will also alert you if you attempt to commit a >100mb file, which github will reject. It will reject the commit, allowing you to revise it to remove or reduce the size of the offending file(s). **These scripts have to be installed individually on each computer you clone the repo to. Please ensure your teammates have installed these as well.** 101 | 102 | 6. On OSX, you must make these hooks executable by chmod +x. https://support.apple.com/guide/terminal/make-a-file-executable-apdd100908f-06b3-4e63-8a87-32e71241bab4/mac 103 | 104 | ## Invite Teammates 105 | 106 | 1. Make sure they've all installed git lfs! 107 | 108 | 2. Add them to your repo. 109 | 110 | 3. Help them clone the repo, copy the `pre-commit` & `post-merge` scripts into `/.git/hooks/`, and setup the .gitconfig file for their system (steps 3-5 of Create & Configure Your Repo). 111 | 112 | # Usage and Errors 113 | 114 | Now that you have these hooks installed, they'll automatically stop you if you try to commit files that might mess up your project. There are a few ways this can happen. 115 | 116 | ## Attempt to Commit File >100MB 117 | If you try to commit a file that's bigger than 100MB, you'll see an error like this one: 118 | 119 | >Commit failed with error 120 | > 0 files committed, 1 file failed to commit: testing 121 | > `Assets/big.pdf` is over 100MB. 122 | > Can't commit, fix errors first. 123 | 124 | Resolve this error by reducing the size of the file. For audio or visual assets, try splitting them into smaller parts or compressing them. For unity .scene files, try to reduce the scene size by dragging elements out of the scene and into prefabs. 125 | 126 | ## Failure to Commit Metafile 127 | If you try to commit an asset without a corresponding metafile, you'll see an error like this one: 128 | 129 | >Commit failed with error 130 | > 0 files committed, 1 file failed to commit: testing . 131 | > Error: Missing meta file. 132 | > Asset `Assets/LensFlare.flare` is added, but `Assets/LensFlare.flare.meta` is not in the git index. 133 | > Please add `Assets/LensFlare.flare.meta` to git as well. 134 | 135 | Resolve this error by adding the corresponding .meta file to your commit. 136 | 137 | ## Failure to Add Corresponding Metafile to Gitignore 138 | 139 | If you add a file or folder to the .gitignore, but don't add the corresponding .meta to your .gitignore, you'll see an error like this one: 140 | 141 | >Commit failed with error 142 | > 0 files committed, 3 files failed to commit: testing 143 | > `LensFlare.flare` 144 | > `LensFlare.flare` found in .gitignore but not the corresponding meta file! Please add `LensFlare.flare.meta` to .gitignore . 145 | 146 | Resolve this error by editing your .gitignore by adding the .meta file to it. 147 | 148 | Always exercise caution when adding to your .gitignore: it's not a tool for resolving bad commits (see the [troubleshooting](#troubleshooting) section for help resolving issues with commits). Never add .meta files to the .gitignore without also adding the file associated with that meta file to the .gitignore. Adding files to your .gitignore will result in them not being backed up & nor shared with your collaborators. 149 | 150 | # Troubleshooting 151 | 152 | Did everything above & still managed to run into a problem? Here are some of the best resources for learning how to restore your repo. 153 | 154 | * [On undoing, fixing, or removing commits in git](https://sethrobertson.github.io/GitFixUm/fixup.html) - A choose-your-own-adventure style troubleshooter 155 | * [Oh shit, git!](https://ohshitgit.com/) - Lots of common use cases, expressed simply & crassly 156 | * [10 Common Git Problems](https://www.codementor.io/citizen428/git-tutorial-10-common-git-problems-and-how-to-fix-them-aajv0katd) - Similar to the above, less crass 157 | * [git-lfs Troubleshooting](https://github.com/git-lfs/git-lfs/wiki/Troubleshooting) - Common issues folks run into while using git-lfs 158 | 159 | # Additional Information 160 | 161 | Want more info on how we built these config files & hooks? Here's some of the docs & posts we read when building this: 162 | 163 | * http://www.gamasutra.com/blogs/TimPettersen/20161206/286981/The_complete_guide_to_Unity__Git.php 164 | * http://www.edwardthomson.com/blog/git_with_unity.html 165 | * https://riptutorial.com/unity3d/example/7179/setting-up-a-git-repository-for-unity 166 | * https://thoughtbot.com/blog/how-to-git-with-unity 167 | * http://teaclipper.co.uk/2016/11/11/the-perfect-unity-git-repo/ 168 | * http://www.jameskeats.com/blogs/post/Unitys-SmartMerge-Meets-SourceTree/ 169 | * https://nagachiang.github.io/tutorial-setup-smart-merge-for-unity-assets-with-git/ 170 | * https://www.forrestthewoods.com/blog/managing_meta_files_in_unity/ 171 | --------------------------------------------------------------------------------