第一步、下载源代码文件(如测试使用的时v2.21.0版本,其他版本类似)
wget https://github.com/git/git/archive/v2.21.0.tar.gz
第二步、安装相关依赖
sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
第三步、编译安装
tar -zxvf git-2.21.0.tar.gz
cd git-2.21.0
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
第四步、检查安装版本,判断是否安装成功
$ git --version
git version 2.21.0
第五步、Git命令补全
(1)、在解压的git-2.21.0目录下:
$ cp contrib/completion/git-completion.bash ~/.git-completion.bash
$ vi ~/.bashrc
(2)、在.bashrc文件最后添加 source ~/.git-completion.bash
然后执行命令使得修改好的 .bashrc文件重新生效
$ source ~/.bashrc
详细参考:
https://blog.csdn.net/chinassj/article/details/80323641
https://www.jianshu.com/p/8e1abe9dc1cc