What are the steps necessary to prepare a Unity project for committing to a git repository eg. github? I don't want to store unnecessary files (specially temp files and avoid binary formats as much as possible).
-
90Oh definitely not. I'll stick to git, thanks– GermanDec 23, 2014 at 10:33
-
hi German, I was mainly just joking, but, svn is definitely easier for UNity projects.– FattieDec 24, 2014 at 11:56
-
2german, I just realised you mention to HIDE meta files. this is completely wrong. Is it a typo? Notice: docs.unity3d.com/Manual/… "by selecting Visible Meta Files" and "2. Enable Visible Meta files in Edit->Project Settings->Editor" It's a fairly basic point that you MAKE VISIBLE meta files for source control, you can see 100s QA on it on the unity forum. what's the confusion here? cheers!– FattieDec 24, 2014 at 12:03
-
1Wow! It's a very unpleasant typo on my side. Thanks for pointing it out (fixed)– GermanDec 24, 2014 at 15:37
-
German, awesome! You know, I was really really worried I had something wrong buddy :)– FattieDec 24, 2014 at 17:01
2 Answers
On the Unity Editor open your project and:
- Enable External option in Unity → Preferences → Packages → Repository (only if Unity ver < 4.5)
- Switch to Visible Meta Files in Edit → Project Settings → Editor → Version Control Mode
- Switch to Force Text in Edit → Project Settings → Editor → Asset Serialization Mode
- Save Scene and Project from File menu.
- Quit Unity and then you can delete the Library and Temp directory in the project directory. You can delete everything but keep the Assets and ProjectSettings directory.
If you already created your empty git repo on-line (eg. github.com) now it's time to upload your code. Open a command prompt and follow the next steps:
cd to/your/unity/project/folder
git init
git add *
git commit -m "First commit"
git remote add origin git@github.com:username/project.git
git push -u origin master
You should now open your Unity project while holding down the Option or the Left Alt key. This will force Unity to recreate the Library directory (this step might not be necessary since I've seen Unity recreating the Library directory even if you don't hold down any key).
Finally have git ignore the Library and Temp directories so that they won’t be pushed to the server. Add them to the .gitignore file and push the ignore to the server. Remember that you'll only commit the Assets and ProjectSettings directories.
And here's my own .gitignore recipe for my Unity projects:
# =============== #
# Unity generated #
# =============== #
Temp/
Obj/
UnityGenerated/
Library/
Assets/AssetStoreTools*
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
*.svd
*.userprefs
*.csproj
*.pidb
*.suo
*.sln
*.user
*.unityproj
*.booproj
# ============ #
# OS generated #
# ============ #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
-
23You may want to refer to gitignore.io for some suggested ignore content.– ChrisFeb 5, 2014 at 13:25
-
1I will add my own .gitignore recipe here, thanks for the advice (makes sense)– GermanFeb 9, 2014 at 12:07
-
1What are the .suo files and why are they kept in gitignore.io? Same question about the Assets/AssetStoreTools* folders(s)– AgostinoJun 7, 2014 at 17:05
-
9As of 4.5, it looks like this option: "Enable External option in Unity → Preferences → Packages → Repository" is no longer in preferences or necessary. I didn't do that, but followed the rest of this, and it worked just fine. Jul 10, 2014 at 20:28
-
12By the way, confirmed everything works as is for Unity 5. Also, thanks a ton, German- this is a true life saver Mar 15, 2015 at 1:02
Since Unity 4.3 you also have to enable External option from preferences, so full setup process looks like:
- Enable
External
option inUnity → Preferences → Packages → Repository
- Switch to
Hidden Meta Files
inEditor → Project Settings → Editor → Version Control Mode
- Switch to
Force Text
inEditor → Project Settings → Editor → Asset Serialization Mode
- Save scene and project from
File
menu
Note that the only folders you need to keep under source control are Assets
and ProjectSettigns
.
More information about keeping Unity Project under source control you can find in this post.
-
1
-
2The "Packages" section is missing in the Preferences in Unity 4.5. What does this setting do actually? Jul 23, 2014 at 12:01
-
1Take a look at the selected answer above, the step "Enable External option in Unity → Preferences → Packages → Repository" is not necessary on Unity 4.5+– GermanSep 1, 2014 at 18:46