How to install Git in CentOS

To Install Git in CentOS

Git is the most versatile control system for software development in Linux distributions. It tracks and handles the file changes in an efficient manner. Git control system aims to maintain a large distributed development project. Many languages are being used to develop this control system including, Perl, Bash, C and Tcl. Installation of Git in CentOS is explained in this article.

Installation of Git

To install Git, first you need to install the required development tools with below command.

[root@linuxhelp1 ~]# yum install " Development Tools" 


Alternative command to install development tools is given below.

[root@linuxhelp1 ~]# yum  groupinstall " Development Tools"  -y
Loaded plugins: fastestmirror, langpacks
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/2): extras/7/x86_64/primary_db                          | 160 kB   00:10
(2/2): updates/7/x86_64/primary_db                         | 7.1 MB   00:52
Determining fastest mirrors
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package autoconf.noarch 0:2.69-11.el7 will be installed
-->  Processing Dependency: m4 > = 1.4.14 for package: autoconf-2.69-11.el7.noarch
-->  Processing Dependency: perl(Data::Dumper) for package: autoconf-2.69-11.el7.noarch
--->  Package automake.noarch 0:1.13.4-3.el7 will be installed
-->  Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch
-->  Processing Dependency: perl(TAP::Parser) for package: automake-1.13.4-3.el7.noarch
--->  Package bison.x86_64 0:2.7-4.el7 will be installed
--->  Package byacc.x86_64 0:1.9.20130304-3.el7 will be installed
--->  Package cscope.x86_64 0:15.8-7.el7 will be installed
--->  Package ctags.x86_64 0:5.8-13.el7 will be installed
.
.
.
Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7
  apr-util.x86_64 0:1.5.2-6.el7
  boost-thread.x86_64 0:1.53.0-25.el7
  dwz.x86_64 0:0.11-3.el7
  gettext-common-devel.noarch 0:0.18.2.1-4.el7
  gettext-devel.x86_64 0:0.18.2.1-4.el7
  kernel-devel.x86_64 0:3.10.0-327.28.3.el7
  libgfortran.x86_64 0:4.8.5-4.el7
  libquadmath.x86_64 0:4.8.5-4.el7
  libquadmath-devel.x86_64 0:4.8.5-4.el7
  libstdc++-devel.x86_64 0:4.8.5-4.el7
  m4.x86_64 0:1.4.16-10.el7
  mokutil.x86_64 0:0.9-2.el7
  perl-Data-Dumper.x86_64 0:2.145-3.el7
  perl-Error.noarch 1:0.17020-2.el7
  perl-Git.noarch 0:1.8.3.1-6.el7_2.1
  perl-TermReadKey.x86_64 0:2.30-20.el7
  perl-Test-Harness.noarch 0:3.28-3.el7
  perl-Thread-Queue.noarch 0:3.02-2.el7
  perl-XML-Parser.x86_64 0:2.41-10.el7
  perl-srpm-macros.noarch 0:1-8.el7
  subversion-libs.x86_64 0:1.7.14-10.el7
  systemtap-client.x86_64 0:2.8-10.el7
  systemtap-devel.x86_64 0:2.8-10.el7

Dependency Updated:
  boost-system.x86_64 0:1.53.0-25.el7    dyninst.x86_64 0:8.2.0-2.el7
  libstdc++.x86_64 0:4.8.5-4.el7         rpm.x86_64 0:4.11.3-17.el7
  rpm-build-libs.x86_64 0:4.11.3-17.el7  rpm-libs.x86_64 0:4.11.3-17.el7
  rpm-python.x86_64 0:4.11.3-17.el7      systemtap-runtime.x86_64 0:2.8-10.el7

Complete!


Then start installing the additional dependencies for further process.

[root@linuxhelp1 ~]# yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Package gettext-devel-0.18.2.1-4.el7.x86_64 already installed and latest version
Resolving Dependencies
-->  Running transaction check
--->  Package openssl-devel.x86_64 1:1.0.1e-51.el7_2.5 will be installed
-->  Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-51.el7_2.5 for package: 1:openssl-devel-1.0.1e-51.el7_2.5.x86_64
-->  Processing Dependency: krb5-devel(x86-64) for package: 1:openssl-devel-1.0.1e-51.el7_2.5.x86_64
--->  Package perl-CPAN.noarch 0:1.9800-286.el7 will be installed
-->  Processing Dependency: perl(local::lib) for package: perl-CPAN-1.9800-286.el7.noarch
-->  Processing Dependency: perl(ExtUtils::MakeMaker) for package: perl-CPAN-1.9800-286.el7.noarch
-->  Processing Dependency: perl(Digest::SHA) for package: perl-CPAN-1.9800-286.el7.noarch
--->  Package perl-devel.x86_64 4:5.16.3-286.el7 will be installed
-->  Processing Dependency: systemtap-sdt-devel for package: 4:perl-devel-5.16.3-286.el7.x86_64
.
.
.
Dependency Updated:
  e2fsprogs.x86_64 0:1.42.9-7.el7          e2fsprogs-libs.x86_64 0:1.42.9-7.el7
  krb5-libs.x86_64 0:1.13.2-12.el7_2       libcom_err.x86_64 0:1.42.9-7.el7
  libdb.x86_64 0:5.3.21-19.el7             libdb-utils.x86_64 0:5.3.21-19.el7
  libss.x86_64 0:1.42.9-7.el7              openssl.x86_64 1:1.0.1e-51.el7_2.5
  openssl-libs.x86_64 1:1.0.1e-51.el7_2.5  pcre.x86_64 0:8.32-15.el7_2.1
  zlib.x86_64 0:1.2.7-15.el7

Complete!


Now its time to download the latest version of the Git by using the " wget" command.

[root@linuxhelp1 ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.xz
--2016-09-10 12:56:21--  https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.xz
Resolving www.kernel.org (www.kernel.org)... 199.204.44.194, 198.145.20.140, 149.20.4.69, ...
Connecting to www.kernel.org (www.kernel.org)|199.204.44.194|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4096264 (3.9M) [application/x-xz]
Saving to: ‘ git-2.10.0.tar.xz’ 

100%[======================================> ] 40,96,264   52.4KB/s   in 1m 40s

2016-09-10 12:58:03 (40.0 KB/s) - ‘ git-2.10.0.tar.xz’  saved [4096264/4096264]


The downloaded package could be extracted with the " tar" command.

[root@linuxhelp1 ~]# tar xvf git-2.10.0.tar.xz 
git-2.10.0/
git-2.10.0/.gitattributes
git-2.10.0/.gitignore
git-2.10.0/.mailmap
git-2.10.0/.travis.yml
git-2.10.0/COPYING
git-2.10.0/Documentation/
git-2.10.0/Documentation/.gitattributes
git-2.10.0/Documentation/.gitignore
git-2.10.0/Documentation/CodingGuidelines
git-2.10.0/Documentation/Makefile
git-2.10.0/Documentation/RelNotes/
git-2.10.0/Documentation/RelNotes/1.5.0.1.txt
git-2.10.0/Documentation/RelNotes/1.5.0.2.txt
.
.
.
git-2.10.0/xdiff/xmerge.c
git-2.10.0/xdiff/xpatience.c
git-2.10.0/xdiff/xprepare.c
git-2.10.0/xdiff/xprepare.h
git-2.10.0/xdiff/xtypes.h
git-2.10.0/xdiff/xutils.c
git-2.10.0/xdiff/xutils.h
git-2.10.0/zlib.c
git-2.10.0/configure
git-2.10.0/version
git-2.10.0/git-gui/version


Next move the Git as the working directory.

[root@linuxhelp1 ~]# cd git*
[root@linuxhelp1 git-2.10.0]#


Once you entered into the source folder, run the below command to start building.

[root@linuxhelp1 git-2.10.0]# make configure
GIT_VERSION = 2.10.0
    GEN configure
[root@linuxhelp1 git-2.10.0]# ./configure --prefix=/usr/local
configure: Setting lib to ' lib'  (the default)
configure: Will try -pthread then -lpthread to enable POSIX Threads.
configure: CHECKS for site configuration
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
.
.
.
checking for library containing mkdtemp... none required
checking for mkstemps... yes
checking for library containing mkstemps... none required
checking for initgroups... yes
checking for library containing initgroups... none required
checking for getdelim... yes
checking for library containing getdelim... none required
checking for BSD sysctl... no
checking for POSIX Threads with ' ' ... no
checking for POSIX Threads with ' -mt' ... no
checking for POSIX Threads with ' -pthread' ... yes
configure: creating ./config.status
config.status: creating config.mak.autogen
config.status: executing config.mak.autogen commands


Finally, execute the ' make install' command to install the Git software.

[root@linuxhelp1 git-2.10.0]# make install
    * new build flags
    CC credential-store.o
    * new link flags
    CC common-main.o
    CC abspath.o
    CC advice.o
    CC alias.o
    CC alloc.o
    CC archive.o
    CC archive-tar.o
    CC archive-zip.o
    CC argv-array.o
    * new prefix flags
    CC attr.o
    CC base85.o
    CC bisect.o
    CC blob.o
    CC branch.o
    CC bulk-checkin.o
    CC bundle.o
.
.
.
rm -f " $execdir/$p"  & &  
        test -z " "  & &  
        ln " $execdir/git"  " $execdir/$p"  2> /dev/null || 
        ln -s " git"  " $execdir/$p"  2> /dev/null || 
        cp " $execdir/git"  " $execdir/$p"  || exit  
done & &  
remote_curl_aliases=" "  & &  
for p in $remote_curl_aliases  do 
        rm -f " $execdir/$p"  & &  
        test -z " "  & &  
        ln " $execdir/git-remote-http"  " $execdir/$p"  2> /dev/null || 
        ln -s " git-remote-http"  " $execdir/$p"  2> /dev/null || 
        cp " $execdir/git-remote-http"  " $execdir/$p"  || exit  
done & &  
./check_bindir " z$bindir"  " z$execdir"  " $bindir/git-add" 


After the installation process is accomplished, run the following command to get the version of Git.

[root@linuxhelp1 git-2.10.0]# git --version
git version 2.10.0
Tag : Git
FAQ
Q
What does the gitk error message "Can't parse git log output mean?
A
This is usually caused by color.diff being set to true in your config. git log outputs log entries in colors when color.diff = true. And gitk can only parse the plain output.

It is recommended (as of 1.5.3) that color. diff be kept off. Use git log --color if you need colored output.

This problem should be fixed since version 1.5.4.
Q
What is Git in CentOS?
A
*Git is a distributed version control system developed by Junio Hamano and Linus Torvalds.
*Git does not use a centralized server.*Git runs on Linux, BSD, Solaris, Darwin, Windows, Android, and other operating systems.
Q
How do I report a bug in Git?
A
Bug reports can be sent to the Git mailing list: git@vger.kernel.org
Please put "[BUG]" in the subject line. You don't need to be subscribed to post; see GitCommunity for more information on the mailing list and other ways of interacting with Git developers.
Q
What can I use to set up a public repository?
A
*An SSH server, an HTTP server, or the git-daemon. Local networks can also use network filesystems, like NFS or SMBFS/CIFS (the Windows networks).

*While there was some controversy over whether SMBFS was a safe solution the latest info indicates that it should be fine.
See the Git tutorial for more details.
Q
Why is git --version not reporting the "full" version number?
A
There is a bit of a chicken and egg problem involved. The build procedure wants to have an already installed Git to figure out the "full" version number. If you are bootstrapping, make clean and rebuild after you install Git once would give you a Git binary that knows what version it is.

GIT-VERSION-GEN script show current (used) Git version, git --version shows Git version used at the time Git was built.