Unity3d source control and Unity3d GIT integration

Unity3d source control and Unity3d GIT integration

Back when I started working as a programmer source control systems didn’t really make much sense as it obviously does now, I was working as a Software Engineer at a local company with a team of 4 and I was the only engineer in the team who was handling source code.

Few months after the company adopted an Agile methodology, other department’s within the organization also merged and there was a lot going on including greater communication across development teams, standardization, and code reusability was one of our development key goals.

In the standardization developer meetings, we decided to begin adopting more viable source control technologies and honestly it all came down to what we all had experience with, some of us at the time knew HG (Mercurial) pretty well but the majority of us were more comfortable with GIT - which then by group decision was adopted as our company source control standard.

From this point forward GIT was used for all company projects and also in my own side projects. I remember the days when I began using GIT and not even remembering which commands to type or even the proper order on when to run them, I started using Source Tree to alleviate not knowing the terminal commands, however it turned out to be harder to me and I felt more comfortable using the terminal as it taught me with repetition how I could initialize a GIT repository, add source code, commit code, and push code, later on I learned a lot about branching and how I could also checked out different branches.

How do I get started with GIT in Unity3d ?

There is really nothing different in Unity3d than you would do in any other framework when adding it to source control, however you will need to ignore few folders or files to avoid having to track files that simply get generated by Unity and those folder(s) or file(s) can be excluded by using a .gitignore file.

To get going with GIT follow the next steps to setup a new repository for your Unity3d project, for demonstration purposes I suggest using bitbucket.org as they provide free public repositories, however you’re welcome to apply these steps to any source control service of your preference.

  1. Enable “Visible Meta Files” in Unity by going to Edit->Project Settings->Editor-> Version Control. This tells Unity to make the project structure compatible with storing assets in an external version control system.
  2. Enable “Force Text” in Unity by going to Edit->Project Settings->Editor-> Asset Serialization.
  3. Go to bibucket.org or a GIT compliant service of your preference and create a new blank repository, then keep a record of the repository URL which should look like git@bitbucket.org:username/[REPO_NAME]
  4. In your local box create a new folder to host your Unity3d project files. Example: C:\Code\MyGameCodeRepository\
  5. Using the terminal change the directory to C:\Code\MyGameCodeRepository\
  6. Using the terminal Initialize your GIT repository by typing “git init”. This step makes everything in the directory a GIT repository which allows you to track any files placed in the directory.
  7. Add a new .gitignore file to exclude auto generated files made by Unity3d or external tools such as Visual Studio, I recommend you use the .gitignore file below:

    # Visual Studio 2015 cache directory
    # Autogenerated VS/MD/ solution and project files
    # Unity3D generated meta files
    # Unity3D Generated File On Crash Reports
    # Builds
  8. Now copy your Unity3d game directory contents to C:\Code\MyGameCodeRepository\

  9. Add all files to GIT by typing “git add -A”, this command will add all files in the current directory and exclude all folder(s) or files(s) from your .gitignore file.
  10. Add a new remote in bitbucket.org by typing “git remote add origin git@bitbucket.org:username/[REPO_NAME]”, this step basically tells your local GIT where the remote GIT url is which is the same URL you recorded on step 3.
  11. Now you need to push your files to the remote by typing “git push -u origin master”.

Additional tips for using GIT in General

  • To avoid having to type your password every time you interact with GIT make sure to use SSH which is built into MAC or you could also use Plink to communicate with your remote in Windows- do few searches online as there’s a lot of information about this topic.
  • Keep your commits as small as possible. I recommend this step to simplify your merges, experiencing what I call nasty merges while working with larger teams is inevitable and keeping them small will reduce it significantly.
  • Learn about branching, I use it a lot when working on different platforms, for instance I branched my code when I was working in iOS and kept a master branch with my MAC/PC branch. After I was done with iOS I merged everything back to the main branch and kept only one branch.
  • Source Tree is a great solution, I recommend learning GIT commands and understanding GIT well and then moving to Source Tree if you prefer a GUI solution.


Thank you for your time and don't forget to subscribe to my newsletter, also be sure to find me at @dilmerv and stop by and say hi as I love to chat with everyone.

Pingbacks are closed.

No comments yet.