Reza Ghobadinic

Storage and a Version Control System (Git)

We should soon be able to start doing some actual coding. But, before that, it would be a good idea to also setup a centralized storage for ourselves and have a versioning control system in place so that we can track changes and have a safe backup of the project somewhere.

My version control system of choice is “Git” from Linus Torvalds. It is a very fast and powerful tool. It is a distributed multi user Version Control System for coding that you can install on Mac, Windows and Linux!

On top of that, I use services from Bitbucket.org for my online repositories. The alternative of course would be github.com. I personally prefer Bitbucket for my purpose! It lets you have private repositories on their servers for free and they have developed this thing called “git lfs” that is basically git for big binary files, like images, movies, scene file types that we will have lots of them while making a game!

We will also need some local storage that we can access easily from any device.

 

Local Storage

I just talked about setting up a remote Git repository in Bitbucket, but I would also like to have some kind of local file server at home for storing bigger data and things that will not necessarily go into the Git repository. Also, I use a few computers for my work at home. Two Macbook Pros and a Dell490 Workstation (Windows and Linux Dual Boot) to be exact! This is also another reason to need a centralized local file server so that I can access my files from all these machines.

However, I am not going to buy a full server to keep it on all the time so that I can access some files. It will be expensive and also hard to maintain and administrate. After all I want to make a game, not spending time handling server and network issues!

So, instead of a dedicated server, I decided to go for a simple NAS with a couple of hard drives connected to it! The NAS connected to my internet router will give access to all my machines at home and I will also have some limited access wherever I can connect to internet.

The NASS I chose is the cheapest Synology (DS115j model) that I could find. I put a 4GB internal HDD inside the NAS drive and connected 2 of the 2GB external portable WD drives I had through the USB ports. In total it became 8GB of storage and that is more than enough for my needs.

The Synology comes with a pretty nice and simple control panel to setup the devices too which works on an Internet browser!

With the local storage out of the way, lets install git, git-lfs and setup a bitbucket account for ourselves.

 

Homebrew

If you are on a Mac like me, you should have Homebrew to install certain software on your Mac easier. What is Homebrew then? According to them “Homebrew installs the stuff you need that Apple didn’t!”. The alternative is “Ports” that does the same thing pretty much! The xcode command tools that we installed on previous posts is needed here btw.

To install Homebrew if you haven’t already, just type this command in a Terminal window:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To update Homebrew to the latest software list, run:

brew update

Now lets get to the real stuff.

 

Installing Git

To install the git files, just follow these simple steps:

apt-get install git

We will get to making a repository later in this post. However, I am not going to have a full git tutorial in my blog as it needs a whole new blog of itself.

 

Installing Git LFS

brew install git-lfs

or this if you use Ports:

port install git-lfs
cd ~/Downloads/git-lfs-1.X.X
./install.sh
git lfs install

 

Setting Up A Bitbucket Account

Git will allow you to create repositories in your local hard disk and track changes in time. But, what if your hard disk crashes and you loose everything or what if you wanted to have access to the same project from different machines and operating systems from anywhere with an internet connection?

This is when an online service comes handy. You can of course buy a NAS and set it up at home to act as a Git server, but the easier and more secure way is to use an online version control service like Bitbucket or GitHub (or any other).

Lets start by setting up ours in Bitbucket:

Next, we will create a new git repository on our local hard disk, add a Cocos2d-x project to it and transfer all that online, to sync with our bitbucket repository.

 

Creating a project and move it to Bitbucket

First we create an empty repository in Bitbucket and then we use that to move our files.

Now we create a local project on our local drive and make it a git repository and then connect it to Bitbucket repository and sync!

cocos new test -p com.rezagn.games -l cpp -d ~/Projects/games/
cd ~/Projects/games/test
git init
git add --all
git commit -m "Initial Commit"
git remote add origin https://rezagnau@bitbucket.org/rezagnau/test.git
git push -u origin master

 

Ignoring the unwanted files in git

We don’t want to track some temporary intermediate files in our Git repository. For example, the *.o files that are generated while compiling a C++ project fall in that category.

To have Git ignore those files, we either create a .gitignore file in the root or our repository or edit the exclude file in the .git/info folder.

If we open the .git/info/exclude file, we will see the contents similar to these:

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.DS_Store

We can now un-comment those that you want added to the exclude list and be ignored and also add new file types too. The other way as I said is to add a .gitignore file in the root of the project and put similar contents as the exclude file in it.

 

Adding Git LFS tracks

We have to tell Git LFS which files it should track. If we want jpg files to be tracked by Git LFS we type:

git lfs track '*.jpg'

This will create a .gitattributes file that we will need to track as well so that you don’t loose which files will be tracked by it. We also have to add the jpg files too after tracking them this way.

git add .gitattribute "*.jpg"

We are done with setting up basic git properties and repository. For more info, please visit git website documentation!

 

Lets start coding now…

Next

Exit mobile version