Monday, February 18, 2013

git for OS X

If you are a programmer, I can guarantee you, you will or should want to use some sort of version control system. Version control is incredibly important, when I first started coding I thought just having a few backups every now and then on a random one of my flashdrives was sufficient, and truth be told, at that stage it was. Nothing I was doing was too hectic, nothing was drastically changing so I was content with a backup regardless of whether or not it was effective.

But lately, in the last 6months or so, I have realised I need something better than just somewhere to plonk my code when I've reached a certain goal. I needed something that would give me control over my code and allow me to: a) have a backup at all times, b) allow me to see what code was added removed and when, to locate bugs, and c) so other people I work with have access to my code without throwing a flashdrive at me or waiting for an email I forgot to send for the thirteenth time.

So I decided I needed some sort of VCS (version control system). I began looking around and was a little disappointed, nothing was very straight forward, everyone used a different system and there were so many systems. The most common ones in my experience are Subversion or SVN, Mercurial or Hg, Perforce, Bazaar and of course git.

NOTE: Please remember these 'systems' are just software, most of them do not have a GUI of any sorts and are almost exclusively command line tools. That said, there are plenty of GUI's available for each but require a separate download. (This confused me for a while, so don't get confused)

I decided to use git, after seeing companies like Google, Microsoft, Linux...and of course, the deciding factor, Android all use git, I presumed it would be a good system.

So I downloaded the install for my mac and tried to install it, but it didn't work. It has taken me till now to realise why and fix it. If you install XCode from the Appstore, along with the command line tools, a version of git will be installed, however, it is rather old and as of yet I have no idea how or if these install can be updated.

Now I will take you through installing git, including editing your bash_profile file on your computer to allow the use of git from where ever. This is something lacking in almost every single tutorial on git which really annoyed me greatly, and so I shan't do that to any one. Here we go:

NOTE: I am working on OS X version 10.8.2 on my MBP 15"

First we need git:
1.You can download it from git-scm.com
2.Double click on the .dmg file: It should look something like this...


 (If this is the first time installing or trying to install git, you can skip steps 3 and 4)

3.Once its unpacked copy the unisntall.sh script to your desktop



4.Open up your terminal (Either default Terminal or iTerm 2) and type sh, then drag the uninstall script onto the terminal and hit enter - follow the instructions that come up:




This script will uninstall any previous git instances on your computer, except the one installed by xcode

5. Once git is completely uninstall, run the install package, the .pkg file.


6. Click 'Continue' and follow the instructions to install git

7. YAY! Give yourself a big hug and pat on the back, you have successfully installed git. Now we need to make it easily callable from the command line. i.e. we don't want to have to find and navigate to  the file every time we want to use it

8. In your terminal type 'git' (no inverted comma's) and hit enter. If you see a whole bunch of commands come up, great, you are done. If not, continue on. It means that git successfully linked to the directory, for me it didn't do this for some reason.

NOTE: If you can use git as is, the next part is unnecessary, however it's useful if you ever install any other tools that aren't mapped, specifically when you build from source.

9. Navigate to your user profile, if you just opened the terminal you are probably already there, if not type, 'cd ~/' (no inverted comma's) and hit enter, you should now be where you need to be.

10. Now type 'nano .bash_profile' (no inverted comma's) and again hit enter

11. You will see a possibly empty, possibly not screen that looks a little like this:


As the name suggests this is your bash profile - most of the commands you call in the terminal are bash commands, and this little file directs your terminal to all your different programs that are accessed by the command line.

12. Now we need to add the path to git, it should be located at 'usr/local/git/bin', if we direct the terminal there we should be able to run git form anywhere. Type 'export PATH=${PATH}:/usr/local/git/bin' (no inverted comma's) into the space provided:


13. Press ctrl+x to exit, y to save and enter to confirm. Close the terminal and open it again, type 'git --version' (no inverted comma's) and you should see this:


The version of your git installation should be displayed.

Now you just have to learn to use git ;-). which is where the fun starts.

I will be writing another post on using git at a later stage. So keep posted :-)If anything isn't clear or work the way  I have described it, please let me know so I can edit the post and help others who may have similar issues.

No comments:

Post a Comment