What are best practices for using Git source control with Unity 3D, particularly in dealing with the binary nature of Unity 3D projects? Please describe the workflow, what paths would be included in .gitignore, what settings should be set in Unity and/or the project, and any other special things that should be noted.
Note: I realize that using the Asset Server is the Unity-recommended way, but I would like to use Git for a variety of reasons. Please no answers that state or argue that I should just use the Asset Server. The Asset Server really isn't an option for me.
When using Git with a Unity project you want to ensure the project uses text versions of its internal files (instead of binary) so it can more readily track and merge changes. Go to Edit > Project Settings > Editor, and ensure Asset Serialization > Mode is set to Force Text. This is the default in new projects.
The following is an excerpt from my personal blog .
Update Oct 2015: GitHub has since released a plugin for Git called Git LFS that directly deals with the below problem. You can now easily and efficiently version large binary files!
Git can work fine with 3D games out of the box. However the main caveat here is that versioning large (>5 MB) media files can be a problem over the long term as your commit history bloats. We have solved this potential issue in our projects by only versioning the binary asset when it is considered final. Our 3D artists use Dropbox to work on WIP assets, both for the reason above and because it's much faster and simpler (not many artists will actively want to use Git!).
Your Git workflow is very much something you need to decide for yourself given your own experiences as a team and how you work together. However. I would strongly recommend the appropriately named Git Flow methodology as described by the original author here.
I won't go into too much depth here on how the methodology works as the author describes it perfectly and in quite few words too so it's easy to get through. I have been using with my team for awhile now, and it's the best workflow we've tried so far.
This is really a personal preference here as there are quite a few options in terms of Git GUI or whether to use a GUI at all. But I would like to suggest the free SourceTree application as it plugs in perfectly with the Git Flow extension. Read the SourceTree tutorial here on implementing the Git Flow methodology in their application.
For an up to date version checkout Github maintained Unity.gitignore file without OS specifics.
# =============== #
# Unity generated #
# =============== #
Temp/
Library/
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
obj/
*.svd
*.userprefs
/*.csproj
*.pidb
*.suo
/*.sln
*.user
*.unityproj
*.booproj
# ============ #
# OS generated #
# ============ #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
For versions of Unity 3D v4.3 and up:
External
option in Unity → Preferences → Packages → Repository
. Edit
menu and pick Project Settings → Editor
:
Version Control Mode
to Visible Meta Files
.Asset Serialization Mode
to Force Text
.File
menu.Check out my blog post for steps on how to do it here.
One of the few major annoyances one has with using Git with Unity3D projects is that Git doesn't care about directories and will happily leave empty directories around after removing files from them. Unity3D will make *.meta files for these directories and can cause a bit of a battle between team members when Git commits keep adding and removing these meta files.
Add this Git post-merge hook to the /.git/hooks/
folder for repositories with Unity3D projects in them. After any Git pull/merge, it will look at what files have been removed, check if the directory it existed in is empty, and if so delete it.
In Unity 4.3 you also had to enable External option from preferences, but since Unity 4.5 they dropped option for that, so full setup process looks like:
Visible Meta Files
in Editor → Project Settings → Editor → Version Control Mode
Force Text
in Editor → Project Settings → Editor → Asset Serialization Mode
File
menuAlso our team is using a bit more extended .gitignore
file:
# =============== #
# Unity generated #
# =============== #
Temp/
Library/
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
obj/
*.svd
*.userprefs
/*.csproj
*.pidb
*.suo
/*.sln
*.user
*.unityproj
*.booproj
# ============ #
# OS generated #
# ============ #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Note that the only folders you need to keep under source control are Assets
and ProjectSettings
.
More information about keeping Unity Project under source control you can find in this post.
What is GIT?
Git is a free and open source distributed version control system (SCM) developed by Linus Torvalds in 2005 ( Linux OS founder). It is created to control everything rom small to large projects with speed and efficiency. Leading companies like Google, Facebook, Microsoft uses GIT everyday.
If you want to learn more about GIT check this Quick tutorial,
First of all make sure you have your Git environment set up.You need to set up both your local environment and a Git repository (I prefer Github.com).
GIT client application Mac/Windows
For GIT gui client application i recommended you to go with Github.com,
GitHub is the place to share code with friends, co-workers, classmates, and complete strangers. Over five million people use GitHub to build amazing things together.
Unity3d settings
You need to do these settings
Switch to Visible Meta Files in Edit → Project Settings → Editor → Version Control Mode.
Enable External option in Unity → Preferences → Packages → Repository
Switch to Force Text in Edit → Project Settings → Editor → Asset Serialization Mode.
Source: Using Git With 3D Games Source Control
To add to everything stated, it is also ideal to use git lfs with Unity. I have been using this since it came out and I had no trouble with it.
You will want to add this .gitattributes
next to your .gitignore
file
*.cs diff=csharp text
*.cginc text
*.shader text
*.mat merge=unityyamlmerge eol=lf
*.anim merge=unityyamlmerge eol=lf
*.unity merge=unityyamlmerge eol=lf
*.prefab merge=unityyamlmerge eol=lf
*.physicsMaterial2D merge=unityyamlmerge eol=lf
*.physicsMaterial merge=unityyamlmerge eol=lf
*.asset merge=unityyamlmerge eol=lf
*.meta merge=unityyamlmerge eol=lf
*.controller merge=unityyamlmerge eol=lf
*.a filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.aif filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.FBX filter=lfs diff=lfs merge=lfs -text
*.rns filter=lfs diff=lfs merge=lfs -text
*.reason filter=lfs diff=lfs merge=lfs -text
*.lxo filter=lfs diff=lfs merge=lfs -text
That is my rolling file list. If you use additional binary files not listed, add them.
I also have files configured to use yamlmerge, you would need to set this up. You can read about it here: http://docs.unity3d.com/Manual/SmartMerge.html
I thought that I might post a simpler .gitignore
for anyone that is interested:
# Ignore Everything
/*
# Except for these
!/.gitignore
!/Assets
!/Packages
!/ProjectSettings
We now have seamless integration to unity with Github to Unity extension... https://unity.github.com/
The new GitHub for Unity extension brings the GitHub workflow and more to Unity, providing support for large files with Git LFS and file locking.
At the time of writing the project is in alpha, but is still usable for personal projects.
The main things to remember when using git for unity-3d source code version control:
(A) DO NOT check-in the Library folder. I have made this mistake multiple times in past and have suffered for it! Delete OR move out library folder before adding your project / files into git.
(B) Use "Visible Meta Files" - for newest unity versions - 5.3.4 and above this happens by default. For some of the earlier versions you need to change the settings under: Edit-> Project Settings-> Version Control
(C) Use a .gitignore file for Unity- to make sure sanity is maintained and files are not unnecessarily added- if on android / tizen - add rules to exclude APK and TPK files from being added to repository. Google around for a .gitignore file for unity OR else use this model .gitignore for Unity provided by GitHub: https://github.com/github/gitignore/blob/master/Unity.gitignore
(D) Make sure the .gitignore file is added to the repository as the first file added - because in past I personally have missed adding .gitignore file. Have many thoughts in hindsight on why this happened- but nowadays I just copy and add .gitignore file as first step of setting up repository.
So... to make a Unity project ready for git, do the following:
(1) Go to project folder
(2) Type git init .
(3) Copy the .gitignore file: On MacOS: cp ~/Downloads/.gitignore On Windows: copy c:\Users[yourusername]\Downloads.gitignore .
(4) git add .gitignore
(5) git add *
Hope this helps... all the best!
Edit -> Project Settings -> Editor
Set Version Control to meta files. Set Asset Serialization to force text.
I think this is what you want.
Only the Assets and ProjectSettings folders need to be under git version control.
You can make a gitignore like this.
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
*.sln
*.suo
*.userprefs
# Mac
.DS_Store
*.swp
*.swo
Thumbs.db
Thumbs.db.meta
.vs/
I would rather prefer that you use BitBucket, as it is not public and there is an official tutorial by Unity on Bitbucket.
https://unity3d.com/learn/tutorials/topics/cloud-build/creating-your-first-source-control-repository
hope this helps.
You can use Github for Unity, a Unity Extension that brings the git workflow into the UI of Unity.
Github for Unity just released version 1.0 of the extension.
Unity also Provide its own Source version control. before unity5 it was unityAsset Server but now its depreciated. and launch a new SVN control system called unity collaborate.but the main problem using unity and any SVN is committing and merging scene . but Non of svn give us way to solve this kind of conflicts or merge scene . so depend upon you which SVN you are familiar with . I am using SmartSVN tool on Mac . and turtle on windows .
I would strongly suggest you switch over to PlasticSCM. It's something Unity has migrated to and provides a designer cum developer workflow to manage version control for something complex like game development.
You can get the cloud edition for 3 users for free. This replaces Unity's Collaborate tool.
Note: I really struggled using Git/Bitbucket and SourceTree for managing a simple project.
https://unity.com/products/plastic-scm
Just adding in on the subjet of Gitignore. The recommended way only ignores Library and Temp, if its wihtin root of your git project. if you are like me and sometimes need unity project to be a part of the repo, not the whole of the repo, the correct strings in gitignore would be:
**/[Tt]emp
**/[Ll]ibrary
**/[Bb]uild
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With