When developing anything it is advised to use a versioning system. At my workplace we use SVN, but I choose to use git for personal projects, and not only because you can store the code on github, it allows for versioning locally, while not connected to the internet.
I’m going to teach you the basics of using git with unity and google drive together, but even if you don’t use unity, you might find this useful.
What is Git?
Git is a versioning system. It allows you to incrementally commit changes, and it stores all the changes you’ve made. If you’ve ever used google docs, it does a similar thing. You can click “All changes saved to drive” and you’ll be shown the version history.
Git is a lot more powerful than that, and has many features for merging changes by different people and collaboration, but as a team of one, all I need is the versioning and the ability to go back.
Never lose any work
If you’re developing open source or public software, using github as your repository is a fine choice, but if you’re developing a private project, you’ll have to pay to store it remotely. That is why I chose to make a local repository for my private projects. I personally use TortoiseGit which has a nice shell overlay and powerful context menu that saves all the hassle of learning and typing commands.
However, storing locally means that if your hard drive dies on you, you’ve lost your work, and we can’t have that!
I personally use google drive for my cloud storage needs. Up until today, I would use TortoiseGit to create a repository inside the google drive folder, and then work in that folder when developing in unity.
The problem is, and I’ve been encountering this for a while, google drive locks the files when trying to back them up into the cloud, making unity throw a bunch of errors in the process.
Furthermore, google drive will try and update files as you change them, every step of the way, not very efficient.
Bare repository
Git has a distinction between a repository you work in, and a repository made only for storing information, a bare repository.
When using Tortoise Git, create a folder with the name of your project inside the google drive folder.
Right click the folder, and chose Git create repository here.
When the dialog pops up, check make it bare.
Now create your unity project outside of the google drive.
After you create your project folder, It’ll look something like this.
Right click the parent folder, and choose Git create repository here again, but this time leave Make it Bare unchecked.
Unity creates a lot of cached files inside the project which aren’t required to be backed up. If you will lose them, and open the project in unity, unity will recreate them. To not commit those files, you’ll need to create or download a .girignore file to tell git not to mind certain files. Here is mine, feel free to use it.
Once you have the .gitignore file in place, you’re ready to commit locally.
The first step is to add all the files to be versioned, right click the parent folder, and click Tortoise Git -> Add.
Go ahead and add all those files.
After the files have been added, git already suggest committing the files, click commit.
Git won’t let you commit anything without a message, so go ahead and type something in. You generally want it to be informative, so I just say first commit, or bare project.
After clicking commit, the changes have been stored locally, but not in the bare repository.
The next step would be to push the changes to the bare repository.
Right click, Tortoise Git -> Push.
Under destination, click Manage.
Under remote, fill in an arbitrary name (no spaces), and under URL paste the path to your repository inside your google drive.
Then click Add new/save.
You should have something like this.
Close it, click ok on the push dialog and it will push the changes to the repository!
If in the future you lose your working copy, you can right click anywhere and click Git Clone. Point it to the bare repository, and it will reconstruct everything.
That’s it. You now have Git working with google drive and unity, without anything stepping on anything else’s toes.
Hope that was helpful.
If you like this post, you may enjoy my two design posts about my steemitjam game.
Theme interpretation: Protect it
Initial design: Settling in