Date: April 19th, 2013
Cate: Technical
Tags: , , , , ,  

Setting up GIT on a Windows computer

I’m just about to start working on a new HTML5 web app (ProjectAnvil), using the Game Closure DevKit.  This devkit basically consists of a local development server with Javascript framework and the ability to compile it into a native iPad/Android app.  Anyway, I followed the instructions for getting it installed on a Windows machine, overall it’s quite straightforward but has required me to install Git on my computer.  Git is a repository and versioning control system that has rapidly overtaken SVN version control in popularity as you can take branches and similar.  This got me thinking that in time I may end up with multiple developers working on ProjectAnvil, so initially setting up my project in a Git repository would be a really sensible move – future proofing you might say.  This proved more complicated than I realised.  GitHub is probably the most popular Git repository about but doesn’t offer private repositories as a free user, it does however offer a quite decent windows GUI.  After a little bit of searching I realised that XP-Dev provides Git repositories and I have an active account with them, bitbucket also offers private repositories for free (the windows application requires .NET 4.5 so isn’t very efficient).  Feeling quite chuffed that I could use my XP-Dev account, I set up a private repository and that’s where the complications began…  To this end I’ve created the set of instructions below in an effort to help people get their computer configured up.  This is a bit technical but I think it’s followable.

A couple of explanations

Firstly, one thing that is not mentioned anywhere, is if you see a command that begins with a $, this means it’s a Git function and needs to be entered within the Git command line editor – called the Git Bash.  You don’t need to enter the $ either, it’s actually the command prompt.  On my Windows 7 machine I found I needed to run the GitBash (msysGit) as an administrator else it threw odd errors up.

Next up it’s worth noting that Git Bash doesn’t handle Windows UNC paths very well so a bit of conversion is needed.  My project folder lives at “E:\gits\projects” and for sake of argument the project folder is going to be called “myproject”.  Git bash will need this to be passed as “/e/gits/projects” for the root project folder – to be honest it’s not that complicated!

Private SSH Key

Private Git repositories require you to create an SSH key, this consists of a private key and public key, which live on your computer as files.  When you do any transaction, the private key is used to encrypt data to the repository server.  The repository server will use the public key to decrypt the information which means you need to give them that key data.

$ cd ~/.ssh
$ ssh-keygen -t rsa -c "username@git.xp-dev.com"
[press enter to confirm]
[enter a passphrase]
[enter the passphrase again]
$ clip < ~/.ssh/id_rsa.pub
$ cat id_rsa.pub >> authorized_keys

This creates you the pair of keys in the Git .ssh folder and authorises them so that you don’t need to keep entering passwords.  The “clip” command copies the public key text to the clipboard so you now need to paste this data to your Git repository company, in my case it was under the account settings on XP-Dev, just a simple right-click paste does the trick.

There are now two variations based on what you’re trying to do.  If the repository is brand new (i.e. you’ve created it at the Git Repository and it contains nothing) then you need to initialise the Repo and push that up.  If the repository already has items in then you need to clone it onto your machine.  You only need to do option a) OR b) not both!

a) To configure a brand new (i.e. empty) repository:

$ cd /e/gits/projects
$ mkdir myproject
$ cd myproject
$ git init
$ git config --local user.name "your git repository user"
$ git config --local user.email "your email address"
$ touch README.md
$ git add *
$ git remote add origin ssh://git.xp-dev.com/myproject
$ git push -u origin master
[you may need to enter your password]

A little explanation.  Because you may be using Repo’s from multiple locations, the git config command configures the settings for this particular git.  The touch command creates a blank read me type file so that you actually have something within the folder, some repository companies moan if you don’t have something.

b) To take a clone of an existing repository

$ cd /e/gits/projects
$ git clone ssh://git.xp-dev.com/myproject

Yeah, sorry it’s not any more complicated than that!  This takes a full copy of the repository onto your computer.

Finally

The instructions above took around 2 or 3 hours of faffing around, basically because I wanted a private rather than public repository and nowhere really explained how to do this.  In reality it should take no more than 15 minutes and didn’t require the use of PuTTy, the full download of Git or any other third party bits of crap that people recommend you clog your machine up with.

The slightly more complicate bit is if you add files to your working copy you need to

$ git add *

and then use

$ git commit -m "Some meaningful commit message"

to push the data up to the repository. If you need to update your copy with the changes from the main repository you need to use

$ git remote update

Personally I can’t be faffed with this and use the GitHub for Windows application to handle my commits and updates.  Once you’ve done either option a) or b) above, you only need to open up GitHub for Windows and drag the whole folder (myproject) onto the window and it will provide a straightforward GUI to allow you to do the necessary.  GitHub for Windows doesn’t like special characters in the ssh connection string or branch name and I find that it refreshes better if you close and reopen it.  But it makes life a lot easier!

Userful links:

Also if you wish to actually setup your README.md file properly, this article provides a useful template.

Leave a Reply

 Name

 Mail

 Home

[Name and Mail is required. Mail won't be published.]