Get in touch

Git Basic

If you're a web developer and you're not using Distributed Version Control System (DVCS), you fall into two categories: 1) You are scared of change or 2) You have found something even better such as flying over the moon on a spoon.

DVCS's allow everyone to all have their own clones/copies of the source code, and branch to their hearts content. You can commit your changes locally and then push them back to a central cloud hosted service when you feel the code is of value to others, then other users can then fetch your updates and enhance the source code.


We've been using the BitBucket repository for a wee while now, and find it to be of great help for startups. There is always the behemoth github if you feel like stepping up the plate.

So where do you start?

I recommend you head on over and download yourself a cheatsheet from Github itself to help you when you're feeling lonely.

First things first, you need to makesure that git is installed and accessible via the command line. We're not going to run through those steps here. Ok, so git is working on the command line, let's proceed.

Set up a new git project (master branch)

> git init

This will tell git to start recording all changes with it's magical wand.

Git will monitor all changes, however, you must tell it what to do with the changes.

What have I done with you lately?

> git status

You should be able to see all changes since the original initialization/last commit. Such as: files not added, files updated, files deleted etc.

So you're ready to commit..

# You have two options here, inline commenting, 
# or adding a comment through default command line
# editor such as vim

> git commit -a

#or through editor
> git commit -m "My first commit"

When you commit your changes, git requires that your file has been added to the list of files it should keep it's version history.

I wanna know what add is?

#Schedules all files to be added to the next commit
> git add .

This is fantastic, now you can add one file at a time if you like, or all of them just by typing the fullstop. But how do you ignore files to be added? Such as nasty cache folders or files specifically for IDE projects.

How to ignore certain files?

# .gitignore file on root folder

Modify the .gitignore folder in webroot. and add the filenames of the files you wish to not include. This can be very handy for password files. It's always best to save a dummy version for new users as a guide to help them set up their config options manually, and ignore your actual config file with passwords.

Another sweet magic trick git does is Branches, lets try that.

Creating a branch and changing the world

# Create a new branch and inherit all the files from 
# current branch
> git branch branchname
# eg. git branch awesomeNewFeature

So what happens now is that a new branch is created inheriting all the files from the current branch. You are now free to use that branch to test and add/update/delete whatever files you want and revert back to your master branch whenever you want. You'll find that down the track you may have separate branches for dev/uat/prod and individual features that you may wish to merge.

Making changes to that branch I just created

> git checkout branchname
# eg. git checkout awesomeNewFeature

By getting an update again, you should see the branch name now at the end of the current folder location. All changes made are only relevant to this branch, you can go back to your master branch at any time

> git checkout master

I want to start using a git project from a remote repository

# make sure you are currently in the folder you wish to add
# the repository to
> git clone

You will be asked for username and password, afterwards, sit back and watch the files fly.

Getting the updates made remotely to my git repository

# Pull and merge changes
> git pull http://domainname/gitproject.git

This will merge the files that have changed, and with luck you shouldn't have to manually go back a manually resolve them.

I'm done, now I want to share my changes with others

# Commit your work locally you crazy banana
# > commit -a "I have done the changes required, bedtime awaits"
> git push

Your changes should now be available for others to pull and clone in safety.


There are heaps and heaps more commands at your disposal, I hope this brief introduction is of help to you.
Good luck in your travels.

Update - 05/09/12
Standard list of extensions to add to gitignore

# Numerous always-ignore extensions

# OS or Editor folders

# Dreamweaver added files

# Komodo

# Folders to ignore

Deploying a website with Git in 6 steps

Here is a quick guide on deploying a website or web app to your production server using Git. If you would like to use something more flexible then check out Capistrano SSH into the remote server ssh -...

Read the full post

Mr Pony Rebrands

Late last year we decided Mr Pony needed to rebrand to reflect who we are and the direction we are taking. We are still working on the new website ( so be prepared to be blown away....

Read the full post

Bonfire - Faster CodeIgniter Development

We came across Bonfire while looking for an authentication library for CodeIgniter to help us kick start a web application we're about to start. Bonfire is a framework built on top of CodeIgniter. It'...

Read the full post