Thursday, 31 January 2013

GitHub for Windows: Git for Beginners

Git is all the rage these days; you can’t move around the internet without bumping into all kinds of comments saying how Git is amazing, distributed SCM systems are the future, and so on. I myself come from the age of Visual SourceSafe (shudder) and TFS where all source-controlled content is locked down until changes need to be made. I have no major complaints about how TFS works – it may be a bit of a beast but it does the job well enough for me – but I can also see the benefits of a distributed SCM system where changes can be made offline and “pushed” to a central repository when ready, which is where Git shines.

GitHub has also helped its popularity by bringing a primarily Linux-based system to the masses, including the Windows crowd. Having said all this Git also has its drawbacks too:

  1. It is entirely command-line based – which is to be expected given its Linux heritage – which initially tends to put some Windows developers off. Now I’m not averse to using command-line tools but sometimes it is just easier to see something visual in front of you.
  2. I also hear that there can be some confusing aspects of Git, such as features that can be used in a variety of ways using various command-line switches. Memorising the commands you need on a daily basis can introduce a bit of a learning curve.

Even so I wanted to try my hand at using it, especially as I had a small project in mind that I wanted to keep track of. But as a complete newbie how do I start? I could follow these steps outlined by GitHub and fiddle around with all kinds of settings and SSH keys, or I could let GitHub help me by using their brilliant client front-end GitHub for Windows.

What is GitHub for Windows? As their website says it’s “the easiest way to use Git on Windows. Period.” It is a desktop application which provides some core features that you would typically use Git for but in GUI form (such as committing changes and branching/merging) but additionally installs all the Git tools you would need anyway; if the GUI can’t do something you can always drop back down to the command-line tools (and it will even help set up your shell to assist you). At the moment I’m just using it for local repositories but I also expect the integration with GitHub itself to be top-notch.

Let’s go over the main features I’ve currently been using.

Installation and Setup

I can’t think of many development tools which are this easy to setup. In the past I imagine that a lot of effort would have been made to download all the Git tools (possibly even having to build them from source), set up environment variables, use various other tools to create SSH keys and so on.

Not so with GitHub for Windows. It all comes bundled as a ClickOnce application; I simply downloaded it, installed it and it setup up everything I would need in the space of about 5 minutes. After that all I had to do was sign-in with my GitHub account and I was ready to roll.

Create a Local Repository


You can of course connect to various repositories that are on GitHub but for the moment I wanted to focus on doing some local development on my own project; I’m not ready to make it public just yet. Again this is simple and straightforward; all I did was create a new repository under the local section and filled in a name and description of it. GFW (as I’m going to now abbreviate it as) then set up those special “.git” folders and initial files and I was ready to commit changes.

Committing Changes


This is actually the bit I’m most impressed with. I can go to Visual Studio and make all the changes I want to, then come back to GFW and it will have seen what has been changed since the last commit, providing you with a mini-diff window for each change made. Even if you delete a file that used to be in the repository GFW will notice it and remove the file on the next commit. Committing changes suddenly becomes incredibly easy and doesn’t require much thinking about.

Branching and Merging


Branching and merging is something that Git is apparently very good at; I had a read though this online book which explained really well how branches work in Git. GFW can handle branches very easily, simply create as many new branches as you want and easily switch between them using the menu.

To merge branches together is also simple; GFW has a branch manager window which shows all the active branches in the repository. To merge simply drag the branches to merge to the bottom of the window and hit the “Merge” button. It really couldn’t be easier.



Ah, and now we hit something that GFW can’t do on it’s own. It is generally good practice to tag releases of projects so you can easily find them in your commit history, but GFW does not support tags out-of-the-box.

Not to worry though, because we can simply use the command-line tools to do that. GFW allows you to open a shell setup for your repository – in my case it opens Powershell using some extra Git extensions. Then I can do something like:

# Add a tag
git tag -a "NewTag" -m "This is a new tag!"

# View available tags
git tag

This is a great example of how, when the GUI does not support what you do, you can always go back to Git as it was meant to be used.

Start of a Beautiful Friendship

I haven’t been this impressed with a piece of software in quite a while. Not only does GFW ease a beginner like me into using Git on a day-to-day basis but it is actually one of the finest examples of a WPF application I’ve seen yet; it is fast, responsive and hasn’t failed me yet.

I look forward to actually pushing my project to GitHub when the time comes!

No comments:

Post a Comment