· git

Introducing my brother to Git

I recently bought a book on Git Version Control, and my brother and girlfriend both looked at me weirdly and asked why I had bought a book on how to be a git. Har-de-har-har. I started trying to explain what it actually was, and my brother was kinda interested. So, this is an attempt to explain it to him, in order to better understand it myself.

What is Git?

Git is a Distributed Version Control System created to keep track of the building and development of the core Linux operating system. It’s used to reliably manage changes made to a project and keep an accurate record of the evolution of the project. Git is used mainly with programming source code, but it can also be used with a variety of files, mainly text, you might want to manipulate and track over time.

Oh right, so what’s version control, then?

Yeah, okay, it still sounds a bit like an obscure programmer’s tool, right? Version control is pretty much what it sounds like, it’s a method for managing the state of a project, through controlling the different versions created when changes are made to it. Here’s a project you’re working on:

So now you have a project folder with these files in:

All of which are basically the same file with changes made to it. And to be honest you’re not entirely sure if that last file has both the suggestions from your friend in it and the most recent changes and not the wild idea still in there. I’ve certainly been there before, and it’s a messy uncertain experience. Add to this further collaboration with other project members and you’ve got a situation where no-one knows for sure if they’re working on the most recent up-to-date version of the project files.

Arrrghhh CATASTROPHE!

With a version control system like Git you don’t have to worry about creating a confusing jumble of filenames. Git allows you to just concentrate on your project and all the content within it. Git takes care of which version of the file you’re working on, logs the history of the changes that have been made, enables you to try wild ideas without buggering up the original file, revert to previous versions and collaborate easily with others.

Okay, I understand that, but I don’t understand what Git actually is … like is it a standalone program?

Well, kinda, but it’s more of a system than a program. Once Git is installed you’ll have access to a set of instructions you can use in the command line/terminal of your computer.

Here, let me show you. In the Git command line on Windows I’m going to start a new project, in a folder called git-formybrother, that contains a single file called test-file.txt. Here, the $ is a command prompt, where the instructions to the computer are typed.

{% highlight bash linenos %} Welcome to Git (version 1.9.5-preview20141217)

Run ‘git help git’ to display the help index. Run ‘git help ’ to display help for specific commands.

$ git init # Initialise the Git repository Initialized empty Git repository in C:/git-formybrother/.git/

$ ls # List the contents of the folder/repository test-file.txt

$ git status # Check the status of the Git repository On branch master

Initial commit

Untracked files: (use “git add …” to include in what will be committed)

    test-file.txt

nothing added to commit but untracked files present (use “git add” to track)

$ git add test-file.txt # Add test-file.txt to Git to be tracked

$ git commit -am “started new project” # Commit the current state of the files, with a short message, to your Git history [master (root-commit) 3110c11] started new project 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test-file.txt

$ git status # Check again the status of the Git repository On branch master nothing to commit, working directory clean {% endhighlight %}

So basically, we’ve just started a new project to be tracked by Git, added a file to it and commited/saved the state of the project to the Git log.

I realise not everyone is comfortable on the command line and this can scare them away, but there are a number of different graphical user interfaces (GUIs), that can make it easier to deal with, and show a nice visual representation of your project, it’s development and the changes made to it. This in itself can provide an incredibly useful overview of what’s going on in your project. Here’s our new project in the Github for Windows client:

Github for Windows screenshot

Okay, but I’m not a software developer, do I really care? Can I really be bothered?

I’m not gonna lie, it’s great but it’s not magic, there’s a learning curve involved, and to be honest I don’t know if it’s a sensible way of managing more complicated files like MS Office files, but you should avoid MS Office anyway. Even so, once you get the basics you’ll be creating and maintaining cleaner, clearer projects with more structure and accountability. Have a go here, see what you think…

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket