- Local storage
- Homebrew
- Installing Git
- Installing Git LFS
- Setting up a Bitbucket account
- Creating a project and move it to Bitbucket
- Ignoring the unwanted files in git
- Adding Git LFS tracks
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:
- For Windows/Mac, download and install the latest version (2.18.0 or higher) of the git program for your system. It is just a standard installation.
- For Linux Debian/Ubuntu/Mint, type this in a Terminal instead:
apt-get install git
- Now typing “git –version” in a new Terminal should print “git version 2.18.0”.
- You can learn a lot about using git by reading the documentation and tutorials in their website.
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
- There is an excellent tutorial page for what Git LFS is and how to install it, here. I’ll try to list a brief version here anyways.
- The easiest way is to go to the Download page of git-lfs and install the binary for your OS.
- If you are on a Mac, you can also use Homebrew (that we just installed) to install git-lfs as bellow:
brew install git-lfs
or this if you use Ports:
port install git-lfs
- For Linux, after downloading the installation file, go to the downloaded unzipped folder and type these commands:
cd ~/Downloads/git-lfs-1.X.X ./install.sh
- The first time you want to use git-lfs, you need to run this command on your system. This is needed only once and after this whenever your repository has git-lfs content, it will automatically initialize git-lfs for you. We will run this when we setup a git repository, so don’t run this just yet!
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:
- From the home page of their website, click on “Get Started” at the top right corner.
- It takes you to the sign up page. Enter your email address there and press “Continue”.
- Next fill out the fields for your name, password, etc… and press “Continue”.
- Follow the instruction on the page to verify your email. Basically from your email you will need to click on a link that they send you.
- Next it will ask you to choose a unique name for your account. Fill that and press “Continue” again.
- If there is a survey page, you can either Skip or Fill the form.
- Done! You should be in your dashboard of Bitbucket account by now.
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.
- Log into Bitbucket Server and create a new repository.
- Change “Include a README?” to No if you want to use the first method of adding files bellow! (Very Important)
- Locate the clone URL in the nav panel on the left and make a copy in clipboard (My example: https://rezagnau@bitbucket.org/rezagnau/test.git).
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!
- Create a Cocos2d-x project in your projects folder.
cocos new test -p com.rezagn.games -l cpp -d ~/Projects/games/
- In a Terminal, change to the newly created project root folder and initialize git.
cd ~/Projects/games/test git init git add --all git commit -m "Initial Commit"
- Push your files to the repository by running the following commands in the terminal (change the URL accordingly):
git remote add origin https://rezagnau@bitbucket.org/rezagnau/test.git git push -u origin master
- Enter your password and press Enter.
- Done. Your project is now in Bitbucket! Make sure to update and push to remote whenever you have new changes that you want to keep.
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…
Leave a Reply