, ,

As I wrote more and more scripts for my work, it become difficult to keep tracking different version of my scripts for different specific tasks. Adopting a source control management (SCM) tool has been put on my agenda. An SCM tool will be even more useful if one is participating a collaborative code development project. There are many such tools available today: Subversions, Mercurial, Git, CVS, etc. I choose Git not only because it is a neat solution in terms of version control but also due to the popularity of Git-based online code development platform, GitHub.

Before we start to install Git, we should already have Apple’s Xcode and command line developer tools together with Macports installed on our mac. You can refer to here for the installation instruction of these prerequisites. Once Macports is installed, all the tools that we installed via Macports will be under the directory “/opt/local/bin/”.

Open a terminal window and follow the commands below.

# update the local ports tree
>sudo port selfupdate
# search for the available git installation
>port search git-core
# list the port variants for git
>port variants git-core
# install git-core together with bash_completion and credential_osxkeychain
>sudo port install git-core +bash_completion+credential_osxkeychain

We still need some configuration.

# Git configuration
# set up user name and user email as the author/commiter for the code
>git config --global user.name "your user name"
>git config --global user.email "your email address"
# enable osxkeychain to store your username and password when connecting to a remote server  
>git config --global credential.helper osxkeychain
# Colorized output:
>git config --global color.branch auto
>git config --global color.diff auto
>git config --global color.interactive auto
>git config --global color.status auto

Now, Git is ready to ready to use. A small test :) >>

>git --help
# you should see
usage: git [--version] [--help] [-c name=value] [--exec-path[=]] ...

Finally, you can find a nice interactive tutorial for Git and GitHub by following this link: http://try.github.io/levels/1/challenges/1