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:

  1. Create a code repo on github.com (or your own Git server).
  2. Create a new project in Unity. Make sure to save it where you want to have your local copy of the code repo.
  3. In Unity, go to Edit > Project Settings > Editor and enable Meta files for Version Control, and Force Text for Asset Serialization.
  4. Quit Unity.
  5. Delete the Library and Temp folder from the project folder.
  6. And now, it's time to make the first commit. Open terminal and follow the next 6 steps.
  7. cd to/your/project/folder
  8. git init
  9. git add *
  10. git commit -m "First commit"
  11. git remote add origin git@github.com:username/project.git
  12. git push -u origin master
  13. Open your Unity project while holding down the Option or the left Alt key. This will force Unity to recreate the Library folder.
  14. 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.
  15. 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.

Latest articles