How to use Git for Unity3D source control?
Solution 1
The following is an excerpt from my personal blog .
Using Git with 3D Games
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!).
Git Workflow
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.
Git GUI Client Application
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.
Unity3D Ignore Folders
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
Unity3D Settings
For versions of Unity 3D v4.3 and up:
- (Skip this step in v4.5 and up) Enable
External
option inUnity → Preferences → Packages → Repository
. - Open the
Edit
menu and pickProject Settings → Editor
:- Switch
Version Control Mode
toVisible Meta Files
. - Switch
Asset Serialization Mode
toForce Text
.
- Switch
- Save the scene and project from
File
menu.
Want you migrate your existing repo to LFS?
Check out my blog post for steps on how to do it here.
Additional Configuration
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.
Solution 2
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:
- Switch to
Visible 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
Also 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.
Solution 3
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
Solution 4
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
Solution 5
I thought that I might post a simpler .gitignore
for anyone that is interested:
# Ignore Everything
/*
# Except for these
!/.gitignore
!/Assets
!/Packages
!/ProjectSettings
PressingOnAlways
I'm a programmer interested in various fields from backend web development to mobile programming. I currently work for an awesome company. Professionally, I work with Ruby on Rails systems nowadays, but I have done everything from Java/Spring/Hibernate to PHP/Symfony to C#/ASP.NET MVP.
Updated on July 08, 2022Comments
-
PressingOnAlways almost 2 years
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.
-
PressingOnAlways over 10 yearsMentioning about git workflow is nice, but perhaps I should clarify in my question I am asking about workflows particularly specific to unity 3D. As you may know, unity projects heavily rely on binary files. Are there any special considerations to deal with this? Some recommendations I found when researching this topic was to use a workflow that avoided merges as much as possible. Perhaps you don't share in this sentiment, but my question is more specific towards unity3d specific issues rather than general workflow preferences.
-
S.Richmond over 10 yearsGit, when presented with binary files, does not diff them for minor changes and only keep the blocks. So git can have problems with its commit history becoming very bloated over time as many versions of a ~4MB texture or 3D model are stored. We deal with this by only versioning the 'final' version of an asset. Our artists use Dropbox to store and work on their WIP assets - Its much faster and simpler that way. NOTE: Added further explanation of this in my post.
-
Jerdak over 10 years
-
S.Richmond over 10 years@Jerdak - Yeah I reviewed git-annex before taking the above approach and found similar: Windows support isn't very good just yet and in the end our artists don't really need that kind of versioning. Using a service like dropbox or gdrive just works so much better for them as they do versioning too (30 versions in gdrive).
-
PressingOnAlways over 10 yearsAn update to this - we tried your setup and it worked pretty well, but we wanted our assets to be automatically synced. We now use sugarsync to selectively sync the binary assets folder. Dropbox would only sync the dropbox folder, but with sugar sync, you can arbitrarily sync folders anywhere on the hard drive which is extremely useful. We had to change our Assets directory structure a bit to define one subfolder for these large binary files, but so far it has worked really well. We just .gitignore that folder and allow sugar sync to keep it in sync.
-
S.Richmond over 10 years@PressingOnAlways yeah we had considered this too, but the problem that arose was that things like prefab connections and references would get lost or broken when an artist moved things around. We needed more control over the assets going into the game. Our team is pretty big though so maybe this would only occur when there are many chefs in the kitchen, so to speak.
-
S.Richmond about 10 yearsMight be better if you edit my answer at the top to include these new options. :)
-
Slipp D. Thompson about 10 yearsWhy the choice to go with
Hidden Meta Files
? -
Slipp D. Thompson about 10 yearsWhy the choice to go with
Hidden Meta Files
? -
Arttu Peltonen about 10 yearsI'm wondering about this choice too. I had problems with hidden meta files previously (although it was an earlier version of Unity so things might be different now), so I've been using visible meta files so far and it's been working well.
-
S.Richmond about 10 yearsFixed my copy n paste typo - Yes it should be Visible Meta Files.
-
Agostino almost 10 yearsPoint one is plainly wrong. There is no Unity → Preferences → Packages → Repository
-
zasadnyy almost 10 years@Agostino thanks for pointing on that, point one was valid in Unity 4.3, updated answer to match Unty 4.5
-
Markus almost 10 yearsaccording to docs.unity3d.com/Manual/… it should be Visible Meta Files
-
aflatoon over 9 years+1 This answer is already written above but @NabeelSaleem answer helped me with images he provided and clear guide :) thanks
-
eifersucht about 9 yearsWorks fine for my team. Thank you very much.
-
Tatanan almost 9 yearsDo I need to push algo the files on the root? I mean: Could I just push /Assets and /ProjectSettings or I have to include the files of /? The reason is that I have a git project for /Assets already. I'd be easier for me to just make a new project for the second folder.
-
S.Richmond almost 9 yearsYou should push the all the contents of the root as a best practice - Many plugins and other more advanced Unity features will utilize the root project folder for various things.
-
Domi almost 9 years
Edit → Project Settings → Editor → Asset Serialization Mode
is worth gold! -
davidkomer over 8 yearsIf not checking in the large files (i.e. assuming they are always sortof placeholders up till the end) - how does this apply to all the prefab wiring in unity? i.e. if I get an fbx file- and I want to keep that just in dropbox... but in unity want the animator / state machine settings to be saved... will this workflow handle that properly?
-
S.Richmond over 8 years@davidkomer you should check-in your binary files as soon as you need them in the project itself. I was primarily pointing out that you're best using Dropbox for a place for artists to pass WIP files around. That said, htere is now a new framework being headed up by GitHub called Git-LFS, which removes the limitations with binary files. Google it. :)
-
Yves Lange over 8 yearsI can't find
Preferences > Packages
in Unity 5.x Normal ? ty -
Yves Lange over 8 years@NabeelSaleem yes. Actually this step in Unity 5.x is not necessary. ty
-
Fattie about 8 yearsAgain, all of these answers are quite out of date on this page. if for some reason you have to use git with Unity, github.com/github/gitignore/blob/master/Unity.gitignore
-
SnapShot about 8 yearsAfter following these steps, cloning the repo to a new location and opening the newly cloned project in Unity the hierarchy window may display with only the Main Camera. If, you see this two items to check: first, verify you are on the correct git branch (if using branches). Second, you may need to select a scene in the project window and double click.
-
Alan Hensley almost 8 yearsDoes anyone else find that even when specifying Force Text for serialization that without the Library folder, Unity thinks the project was created prior to 5.0 and re-imports the library? Is that a problem?
-
Nikhil almost 7 yearsWhy are the .sln and .csproj files excluded? Aren't those needed to maintain project structure?
-
S.Richmond almost 7 yearsNope. They get regenerated by Unity as required.
-
shinzou over 6 yearsAnd then how do you set up YAML merge?
-
Nabeel K about 6 yearsdid you try this ?
-
Isaak Eriksson almost 6 yearsSmall, simple and fully compatible with all versions: I find this script works the best, even for Unity 2017 and 2018 that have recently changed their project structure (
UnityPackageManager/
andPackages/
). -
Thaun_ almost 6 yearsDont forget this: docs.unity3d.com/Manual/SmartMerge.html , a way that fixes merge issues.
-
Furkan Kambay over 5 yearsThere is now a tool for Unity that sets up Git and LFS, and also creates a .gitignore and .gitattributes for LFS. GitHub for Unity was released in June 2018 and is still being developed.
-
Fattie almost 5 yearsRegarding the empty directory idiocy in git, of course you just use a .gitkeep file.
-
S.Richmond almost 5 years@fattie .gitkeep files do the opposite of the problem presented, which is empty dirs NOT being removed when they should. What part of the post is out of date?