How to install the latest GIT version on CentOS

Contents

  • 1.1: Git- An Overview
  • 1.2 Step-by-Step Guide on the Installation and Use of GIT on CentOS
    • 1.2.1 Step 1: Installing Required Packages
    • 1.2.2 Step 2: Downloading and Compiling Git Source
    • 1.2.3 Step 3: Checking the Git Version
  • 1.3 Getting Started with the Initial Git Setup
    • 1.3.1 Initial Git Set Up
    • 1.3.2 Your Identity
    • 1.3.3 Your Editor
    • 1.3.4 Your Diff Tool
    • 1.3.5 Checking Your Settings
    • 1.3.6 Seeking Help

1.1 Git-An Overview

Git is a fairly popular free open source distributed Version Control System (VCS) expressly designed to tackle projects of varying scales (from the small ones to the significantly large ones)with incredible speed and efficiency. It is mainly used for source code management, and remains primarily focused on speed, seamless support for distributed non-linear workflows and data integrity. This tutorial explains the process of installing and using GIT on CentOS in a detailed manner.

1.2 Step-by-Step Guide on the Installation and Use of GIT on CentOS

Installation of Git on CentOS remains a fairly simple process, steps for which have been outlined below:

1.2.1 Step 1: Installing Required Packages

In order to install Git, you need to ensure that the required packages have been installed on the system. Please key in the following command to install the required packagesbefore you begin compiling the Git source:

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils

1.2.2 Step 2: Downloading and CompilingGit Source

Once installation of the required packages is done, you must download the Git source code from the kernel git. You may use the following command to download Git:

cd /usr/src
wget https://www.kernel.org/pub/software/scm/git/git-2.0.1.tar.gz
tar xzf git-2.0.1.tar.gz

The latest Git version at this time is 2.0.1. To find the latest available version when you follow this guide, go to this URL https://www.kernel.org/pub/software/scm/git/ and search for the git-VERSION.tar.gz with the highest version number.

Once you have successfully downloaded and extracted the Git source code, please key in the following command in order to compile the source code:

cd git-2.0.1
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc

The above command shall help you compile the source code, and you are not ready to move on to the next step.

1.2.3 Step 3: Checking the Git Version

The above steps successfully install the Git in software on your system. However, Git is a highly versatile software that comes in various versions to suit the requirements of users across the board. Every version has different commands to fetch the desired data. So, before you start using this software, you should know exactly what version you are using. This will help you to derive the desired results quickly. The command to check the version of Git is:

git -version

This command is very useful for new users in particular as they can seek help from online user manuals by going to the appropriate version.

1.3 Getting Started with the Initial Git Setup

1.3.1 Initial Git Set Up

Now that you have successfully installed Git in your system, you would be eager to customize the software as per your own requirements. Customization of Git is rather easy and once done it remains there even if your upgrade the software. In case you want to change them, you can do so simply by repeating the commands.

With Git you have the convenience of gitconfig, an effective tool that allows you to set configuration variables as per your needs. These variables ultimately decide how your software looks and operates. You can store these variables in three different places: " /etc/gitconfig file: This file stores the values and repositories of all the system users. When the option - -system to gitconfig is pressed, Git reads and writes from this file only. " ~/.gitconfig file: This file is user specific and when you pass the option -global, Git reads and writes specifically to this file. " config file in the Git directory (that is, .git/config) of the repository you're using: This file is again specific to the single repository that you are currently using. In this file each level overrides values in the previous level and consequently the values in .git/config file override the values in /etc/gitconfig.

When you are using a Windows system, Git looks for the .gitconfig file in the $HOME directory (%USERPROFILE% in Windows' environment), which is C:\Documents and Settings\$USER or C:\Users\$USER for most people, depending on version ($USER is %USERNAME% in Windows' environment). Though Git is relative to the Msys root, it still looks for /etc/gitconfig when you install it on your Windows system or when you run the installer.

1.3.2 Setting up User Identity

Whenever you install the Git software in your system the most important thing to do is setting your user name and email address. In fact, this should be your first task as every Git commit uses these credentials and the information provided in them remains unchanged when you pass around.

gitconfig --global user.name "John Doe"
gitconfig --global user.email [email protected]

This has to be done just once if you pass the -global option. This is because Git will automatically use these credentials for anything you do on that system. In case you do not want to use this information for a particular project, you can simply run the command with the --global option.

1.3.3 Configuring the Editor for the User

Once you have set up your identity, you can configure the default text editor in your system. Git uses this editor by default whenever you type a message. Most of the systems have Vi or Vim as the default editor; however if you want to use a different editor like Emacs etc. you can use the following command:

gitconfig --global core.editor emacs

1.3.4 Configuring the Diff Tool

The default diff tool is one of the highly recommended options for Git users. This is because the option comes as a handy tool to resolve minor day-to-day conflicts. There are a variety of such applications available for you; vimdiff being the most common. To configure vimdiff in your system you can use the command:

gitconfig --global merge.tool vimdiff

Git being a widely used software is compatible with most of the diff tools. The most commonly used diff tools include kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff.

1.3.5 Checking Your Settings

Another highly effective feature of Git is that it allows you go check your setting at any given point in time. The single command gitconfig -list gives you a complete list of all your settings. Once you pass the command $gitconfig -list you will get the details as:

user.name=JohnDoe
[email protected]
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto

As Git reads the same key from different files, you may see the same key many times on the screen. For example if Git is reading the same key from /etc/gitconfig and /gitconfig files, it will use the last value represented by the key. In such a case, you may find out how Git is giving value to a specific by using the command:

gitconfig{key}:

$ gitconfig user.name
LizTaylor

1.3.6 Seeking Help

Though Git is a highly versatile software, at times you may need help while using it. However, getting help on Git is as easy as using it. It offers three different ways to access the manual page (manpage):

git help 
git --help
mangit-

For example, to get manpage help for the config command, you simply have to use the following command:

git help config

The best part about the manpage help is that you can access is anytime and anywhere. Git offers you the manpage help even when you are offline. Some beginners and even seasoned users need in-person help for certain tasks on Git. Round-the-clock help is available for such users at #git or #github channels on the Freenodes IRC server. These channels have a heavy presence of seasoned Git users who are willing to help their fellow users.

Share this page:

4 Comment(s)