Version Control with Git

This tutorial is written in the hope that it can give you an overview of Git, Github and version control in general – be it for web developement or software development purposes alike. It will hopefully outline why Git (and version control) is used, the advantages to it and it should give you a brief introduction to using it yourself.


Git

Git is a distributed version control system, similar to popular variants like SVN and CVS, in that it helps manage software development, but it’s also very different too, as it’s built with a completely different method in mind. It was created by Linus Torvalds in 2005 as a piece of version control software that focused primarily on performance and it’s currently being maintained by Junio Hamano, a Google Engineer. Many major companies now use Git like Twitter, Google and Microsoft (as you can see on the Git homepage) and it has become a popular solution to the slower version control systems.

In layman’s terms, Git allows people to work collaboratively on a project from different locations by pulling the source code from the server. It is then part of a local repository on your machine where you can work on it, commit changes and when you’re finished you can then push it back to the server (also known as the master branch) with a message of what you’ve changed.

The best place to learn the theory behind Git and distributed version control systems is on the Git documentation which outlines in great depth, from start to finish the Git system.

Visit Git Documentation


Github

Github is a popular social-coding website which hosts public and private Git repositories. It was first made available three years after Git itself, in 2008, and reported 100 million users in 2011. What differentiates Github from other online repository providers is that it claims to be social – it incorpoates user profile pages and follower counts to help track users commits and comments. It’s free to host a public, and therefore open-source, repository on Github but private repositories are also available for a cost (minimum $7 per month).


Getting Started

Git, the version control software, is open-source and so it can be installed on any machine you like and in this tutorial we will talk about using Git with Github as it’s the simplest way to get started.

1. Sign Up

If you’re not already a member, you’ll need a Github account – which you can sign up for easily on their website.

Sign up to Github

2. Create a Repo’

Once you have a Github account you can then make your very own repository, giving it basic details like a name, description, permissions and if you want a basic initial setup or not (worth agreeing to).

3. Install Git

You will then need a copy of the Git Core installed onto your computer, which is all explained on the Git Documentation website.

Windows: Download Git for Windows & Open Git Bash

OS X: Download Git OSX Installer

Linux:

sudo apt-get install git-core
sudo yum install git-core

4. Setup Git with Your Details

Provide Git with your name and e-mail so it knows who the commits are made by.

git config --global user.email "you@example.com"
git config --global user.name "Your Name"



5. Clone Source

You can now clone your newfangled Git repository onto your computer. If you have ssh and unique keys already setup then you can connect to Github with an ssh address, if not then you can use the HTTP address with the command below (the difference being that with HTTP you must provide a Github username and password):

HTTP:

git clone https://github.com/<your_username>/<repo_name>.git

SSH:

git clone git@github.com:<your_username>/<repo_name>.git

6. Commit Changes

Great! So you should now have a copy of the source on your machine, at your disposal to what you like with. After you have made any changes to the code, the it’s important to make commits regularly – which are like save points.

Add any changed files to the commit:

git add example.txt

Check which files are added, and if you’re missing any:

git status

Commit the code to the local repository:

git commit -m "Example Changed"



7. Push to Finish

Any commits made in the previous step were only made locally, but you can push the changes to the Github servers when you are ready with the push command and stating the origin as master.

git push origin master

Github will then ask for your Github username and password and if the ones provided are correct the master branch at Github will become updated.


Conclusion

This tutorial has only touched on the basics that Git can provide. It is a tool which when used correctly can provide a wonderful base for programming by saving time, allowing for collaboration and allowing developers to see where the project has been and is going. In this day and age it is worth getting into and becoming acquainted with.

Other great places to learn Git include:

Visit Try Git

How did you get on with Git? Let us know in the comments below.

Photo by Roger Hsueh

Leave a Reply