Many of Unity developers work alone. They often start from youtube tutorials from which it’s worth to begin. In small one-person projects, you will think that you don’t need extra program to manage your game files. Sooner or later you will start work with bigger team and then you will need help of external programs to collaborate with other people. Sure you can hold your project in cloud like a Dropbox or on company's server hard drive but in my opinion this is not optimal way to handle teamwork with Unity. In this case the best option is to start use Version Control System.
A version control system (VCS) watching the changes you’ve made to assets in your project. The name of your local copy of project is “working copy”. These changes are stored in a remote database named a “repository”. Every time you change something in your working copy, you need to commit those changes to the remote. The VCS compares what’s already changes in particular commit and only stores the differences. This solution allows the repository be small as possible. For me version control is one of the most important tool in my arsenal. Million times it saved my life. With VCS you can easily roll back changes if you accidentally break or delete something. You can also compare older and newer version of your code to see what’s different. And finally this is an invaluable support for teammates when one of them overwrites other person work by mistake.
A version control systems divide on three types:
Centralized VCS (like SVN) are based on idea of a single “central” copy of your project (probably on a server). Programmers will commit their changes to this central copy. Centralized VCS causes that programmers no longer have to keep copies of files on their hard drives manually. This kind of VCS allows retrieve any need version on the fly.
Distributed VCS (like Git) do not necessarily rely on a central server to store all versions of project’s files. Every developer clones a copy of repository and has the full history of the project on their local hard drive.
The advantages of using distributed VCS are:
Disadvantages of using distributed VCS:
In University of Games we use centralized VCS: Git solution called Bitbucket.
I will show you how to start use Bitbucket in your projects. Why Bitbucket? It is free up to 5 users and unlimited for private repository. In pair with Bitbucket we use SourceTree - a user-friendly GUI that works with Git and Bitbucket.
Using SourceTree to create a repository
Open SourceTree and login using your Bitbucket login and password. Then SourceTree will ask you about clone your first repo. If you didn’t create any earlier simply click “Skip Setup”
After finished setup click Clone/New icon in left up corner:
Choose your destination path and repository name then click Create. Done! You have created your first local repository.
Clone remote repository from Bitbucket
Firstly you need to create a new repository on Bitbucket website. Choose Repositories -> Create repository. Next enter repo name and click Create repository.
Next go back to SourceTree and click Clone/New icon.
Click on the earth planet icon and choose your remote repository from the list. Then name project and click Clone.
Populate your repo with Unity Project
Simply open repository's folder in explorer, then drag and drop Unity project files to this folder. After that you should see all project files in ‘File status window’. As you can see we have a lot junk here. What we can do with it?
Git reads special .gitignore file to know which files it should omit. Create new file in notepad copypaste code below. Save it as .gitignore (Do not forget remove .txt extension!) and move this file to the repository folder.
# =============== # # Unity generated # # =============== # Temp/ Obj/ UnityGenerated/ Library/ # ===================================== # # Visual Studio / MonoDevelop generated # # ===================================== # ExportedObj/ *.svd *.userprefs *.csproj *.pidb *.suo *.sln *.user *.unityproj *.booproj # ============ # # OS generated # # ============ # .DS_Store .DS_Store? ._* .Spotlight-V100 .Trashes Icon? ehthumbs.db Thumbs.db
Now without library and .meta files it looks more clearly. Click Stage All and enter commit name. Finally click Commit to create your first commit.
Finally, Push your changes to remote.
Click Push icon to send your changes to remote
Now you can check on Bitbucket website applied changes. Other members of your project can download this changes by clicking pull in their SourceTree.
Today we have learned how use version control systems in work with Unity. With that tools work with team will be much easier. Using Git or SVN is really better way to handle cooperative work than Dropbox for example. I promise you in crisis situations there is no better friend than commits in your remote repository. There is a one alternative for VCS is a Unity service called - Unity Collaborate. Certainly I tell you about it another time.
I hope it’s useful for you. If you have any comments or questions, please write them here!
Mateusz Olszewski - Lead Programmer