下载git2.x版本:
https://github.com/git/git/tree/v2.13.1 找个稳定版本,找个最新Tag就行了 
https://www.kernel.org/pub/software/scm/git/ 从这下载

安装:

环境: CentOS 7.x,git采用最常用的./configure && make && makesintall 方式安装。但在安装过程中可能会报错,需要安装一些依赖,具体步骤如下:

//卸载
# yum remove git

# cd /usr/local/
//1、下载
# wget https://www.kernel.org/pub/software/scm/git/git-2.13.1.tar.gz
# cd git-2.13.1

//2、执行./configure,会报错
# ./configure
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... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/git-2.13.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

//安装gcc依赖,之后再执行./configure 就不会报错了
# yum -y install gcc


//3、编译,报错:缺少zlib的头文件,开发包没装,
//yum install zlib (系统默认已经装上)
//yum install zlib-devel
# make
GIT_VERSION = 2.13.1
* new build flags
CC credential-store.o
In file included from credential-store.c:1:0:
cache.h:40:18: fatal error: zlib.h: No such file or directory
#include <zlib.h>
^
compilation terminated.
make: *** [credential-store.o] Error 1

//安装zlib-devel
# yum -y install zlib-devel

//4、编译,报错:缺少perl
# make
...
BEGIN failed--compilation aborted at Makefile.PL line 3.
make[1]: *** [perl.mak] Error 2
make: *** [perl/perl.mak] Error 2
# yum install perl-ExtUtils-MakeMaker package

//5、安装支持https
# yum install libcurl-devel


//6、make && make install
# make
# make install

:git clone时候提示fatal: Unable to find remote helper for 'https'

yum install libcurl-devel

然后按照上诉步骤重新安装编译git即可。

检查

# vim /etc/bashrc
export PATH=$PATH:/usr/local/bin/git
# source /etc/bashrc

# git --version
git version 2.13.1

常见问题:

​https://github.com/c-rainstorm/blog/blob/master/tools/compile-install-lastest-Git.md#git-compat-utilh28025-fatal-error-opensslsslh-no-such-file-or-directory​

参考: