I've been a fan of svn for a few years now, due in some large part to the fact it's the only VCS I've ever used. I was introduced to it in 2007 while doing some work for Versatilia. We still use SVN at Versatilia - along with some custom SVN properties and scripts which I'll write about in the future.

However, there's been a lot of fuss over git recently, and with due reason. It was created by Linus Torvalds, godfather of linux. Git has a few key differences with svn. The one that I like most so far is partial commits. However, I've only been trying git for 24h, and there's much more for me to learn.

I reccently had my first experience with git, and github. I've got to admit, I was impressed at how easy it was to create my first repository.

I'm using github as my git repository, as I like the idea of social coding. This meant that I needed to get set up on the site. I was already registered, but hadn't done anything on there. I needed to set up ssh access so I could push changes to the site. This was simple enough to do with the following command:

ssh-keygen -t rsa

I didn't specify a passphrase as I wanted passwordless pushing enabled.
Your public key then needs copying onto github at https://github.com/account#keys. To get your key, run the following command. Make sure there are no line breaks or anything when you copy it to github.

cat ~/.ssh/id_rsa.pub

The next step was to install git on my system. Make sure to install git-core and not git, as I made this mistake. git is apparantly "gnuit"

sudo apt-get install git-core

Your name and email address needed to be set, as they're embedded in the commits that you make. I chose to set them globally as they won't change in many projects.

git config --global user.name "Michael Heap"
git config --global user.email m@michaelaheap.com

If you want to use a name and email for just one project, cd into your local git repo and run git config without the --global flag.

Git, like svn, will launch a text editor when it needs some user input (e.g. to specify a commit message). I like nano as it's nice and lightweight, so I set it as my default editor for git.

git config --global core.editor nano

Now that git was configured on the system, it was time to create my first repo. It was as easy as changing to the correct directory and typing git init
Initialise repo

michael@november:~/ci_theme$ git init
Initialized empty Git repository in /home/michael/ci_theme/.git/

My next step was to add the theme class and commit the change

michael@november:~/ci_theme$ git add Theme.php
michael@november:~/ci_theme$ git commit -m "Initial Theme Library Commit"
Created initial commit 8262f24: Initial Theme Library Commit
1 files changed, 88 insertions(+), 0 deletions(-)
create mode 100644 Theme.php

The file was then committed to my local git repository which is a start, but not very useful for me. I needed to get it up to github somehow. This was done using the git remote command in conjunction with the URL that github provided me with when I created a new repo at URL.

michael@november:~/ci_theme$ git remote add origin git@github.com:mheap/Codeigniter-Theme-Library.git
michael@november:~/ci_theme$ git push origin master
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 1.07 KiB, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:mheap/Codeigniter-Theme-Library.git
* [new branch]      master -> master

I refreshed github, and there it was. My first git commit was painless! Now, I just need to keep committing locally and push to github once I have a public release available.

I don't know why I put off trying git for so long. I think it was all of the origin/master stuff for adding a remote repo. Now that I know I don't need to memorise it and type it every time I want to commit, git is looking a lot more attractive.

Related posts:

  1. Codeigniter Partial Library