Setting up a Unity project with Git
This is the simplest way I have found to setup Git with Unity.
In the document Using External Version Control Systems with Unity, Unity doesn't mention Git as an alternative. I prefer using Git for versioning and just did a test using github.com. Setting up the respository was just as easy as described in the documentation.
Since committing to a git repo is a bit different than committing to svn, I have listed the steps here:
- Create a code repo on github.com (or your own Git server).
- Create a new project in Unity. Make sure to save it where you want to have your local copy of the code repo.
- In Unity, go to Edit > Project Settings > Editor and enable Meta files for Version Control, and Force Text for Asset Serialization.
- Quit Unity.
- Delete the Library and Temp folder from the project folder.
- And now, it's time to make the first commit. Open terminal and follow the next 6 steps.
- cd to/your/project/folder
- git init
- git add *
- git commit -m "First commit"
- git remote add origin firstname.lastname@example.org:username/project.git
- git push -u origin master
- Open your Unity project while holding down the Option or the left Alt key. This will force Unity to recreate the Library folder.
- You can either contine to use git from the command line, or use a Git client like Tower or any other. In Tower, I would choose to Add Local Repository and point it to the folder where I created the Unity project. You don't have to clone the repo because you already set up the repo when doing your first commit.
- Make Git ignore the Library and Temp folder so that they won't be pushed to the server. Add them to the .gitignore file and push the ignore to the server.
I still have the problem of resolving conflicts in the scene files. I guess I could build my games so that the scenes reads settings files and builds up the levels programmatically, but that would in many cases defeat the purpose of the Unity Editor.
NOTE: There are others who have had the same thought of setting up the project with nothing in the scene files. Read the thread Version control workflow at Unity Answers for a couple of hints on how to do it.