Select Page

Git is fast becoming the defacto code versioning system used by professional developers.

Developed by Linux creator Linus Torvalds, Git is an open source, distributed version control system.

Being distributed gives it many advantages over it’s older rival SVN, being able to commit and create branches locally without access to a central server, to name just one.

It scales from massive projects with hundreds of developers right down to a one-man shop, perfectly.

As most deployments are now on VPS or cloud hybrids, they may not always come with Git fully installed.

Here’s how to install Git on a CentOS 6 machine., first using the easy method, then manually to get the latest version of Git.

Installing Git Using Yum

[codelet]sudo yum install git[/codelet]

This does require perl to be installed on the server also.

If you get the following error “Requires: perl(Error)” then install Perl on the server first

[codelet]sudo yum install perl[/codelet]

Installing Git Manually from Source Code

This is a little bit more hands on but will give you greater control and the latest version of Git.

The CentOS repository as of this article contains Git v.1.7.1.3 whereas the latest version of Git is 1.8.5.1 which is quite a difference.

If you’re using Git repos collaboratively with other developers or companies then you want to make sure you’re using the most up-to-date version of Git.

Before installing Git we have to install the Development Tools from the CentOS repository which includes the compiler used to compile the source code.

[codelet]sudo yum groupinstall “Development Tools”[/codelet]

We also need to install some other dependencies to get the Git source to compile and run.

[codelet]sudo yum install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel[/codelet]

Ok – now we’re ready to get the latest zip of Git from github.com and compile it.

Create and move into a tmp folder in your home drive

[codelet]cd ~md tmp[/codelet]
[codelet]cd tmp[/codelet]
[codelet]wget -O git.zip https://github.com/git/git/archive/master.zip[/codelet]

With the master.zip file downloaded, unzip it and move into the folder git-master.

[codelet]unzip git.zipcd git-master[/codelet]

Now we can make the configuration file, give it the parameters it needs and compile the source into a binary file we can run along with related docs.

[codelet]make configure[/codelet]
[codelet]./configure –prefix=/usr/local[/codelet]
[codelet]make all doc[/codelet]
[codelet]sudo make install install-doc install-html[/codelet]

The compilation will take a few minutes to run through to completion.

When finished run Git at the command line to make sure it’s installed properly.

[codelet]git –version[/codelet]

OUTPUT

[codelet]git version 1.8.5.GIT[/codelet]

Once installed you can simply keep Git up-to-date by using itself to clone the github.com repo into a new folder then run the build and install process again.  How handy!

[codelet]git clone git://github.com/git/git[/codelet]

Configuring Git

There is one last step to follow and that’s to configure Git with your details.

When committing files to a git repo it stores your name and email along with the commit information so that changes can be tracked back to a single developer.

These need to be set up otherwise Git my try and use your VPS username and host email for commits.

[codelet]git config –global user.name “Enter Your Name Here”[/codelet]
[codelet]git config –global user.email “[email protected]”[/codelet]

The information is stored in a .gitconfig file in your home folder.

[codelet]cat ~/.gitconfig[/codelet]

You can edit this information at any time.

Or you can check the information directly from Git

[codelet]git config –list[/codelet]

OUTPUT

[codelet]user.name=Wil Brown[/codelet]
[codelet][email protected][/codelet]

Summary

Congratulations – you now have Git working on your CentOS 6 VPS.

Git is a totes amazeballs versioning system that can be use for things way beyond just code.

Explore and have fun.