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 Yumsudo yum install git
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 firstsudo yum install perl
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.188.8.131.52 whereas the latest version of Git is 184.108.40.206 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.sudo yum groupinstall “Development Tools”
We also need to install some other dependencies to get the Git source to compile and run.sudo yum install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel
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
cd ~md tmp
wget -O git.zip https://github.com/git/git/archive/master.zip
With the master.zip file downloaded, unzip it and move into the folder git-master.unzip git.zipcd git-master
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.
make all doc
sudo make install install-doc install-html
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.git –version
OUTPUTgit version 1.8.5.GIT
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!git clone git://github.com/git/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.
git config –global user.name “Enter Your Name Here”
git config –global user.email “firstname.lastname@example.org”
The information is stored in a .gitconfig file in your home folder.cat ~/.gitconfig
You can edit this information at any time.
Or you can check the information directly from Gitgit config –list
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.