Photo by Martin Sanchez / Unsplash
How version control can save your life?
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. In this article we talk about is it worth to use version control system?
What is Version Control?
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.
Tools
A version control systems divide on three types:
- local — allows save data only on local computer (e.g., SCCS, RCS)
- centralized — client — server architecture (e.g., CVS, SVN)
- distributed — P2P architecture (e.g., Git, Mercurial, Bazaar)
Distributed VS Centralized
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:
- Local actions other than pushing and pulling changes are pretty fast because tools do not need a remote server
- Commiting changes can be done locally only. Once you have certain that’s everything is allright, you can push to remote
- Everything but pushing and pulling can be done without an internet conenction
Disadvantages of using distributed VCS:
- If your project contains a lot of large binary files, the space needed to store all version of these files rises quickly.
- If your project has a very long history (50,000 changesets or more), downloading the entire history can take an impractical amount of time and disc space.
In University of Games we use centralized VCS: Git solution called Bitbucket.
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.
Download SourceTree — Go to http://www.sourcetreeapp.com to download and install
Sing up a Bitbucket account — Go to http://www.bitbucket.org and create a free Personal Account following the instructions.
Using SourceTree to create a repositoryOpen 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 BitbucketFirstly 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 ProjectSimply 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.
Conclusion
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!
To help us create more free stuff, consider leaving a donation through Patreon where you can vote for the next asset pack and get access to future packs & articles earlier. Sharing knowledge is our passion. Unfortunately, keeping a team of professionals costs a lot that’s why we are constantly taking on new opportunities.
We’ll be publishing any news on the following outlets:
Thanks for reading!
Leszek W. Król
On a daily basis, I accompany companies and institutions in designing strategies and developing new products and services.