Installing a Newer Version of Git on Linux Using Yum

2021/04/14

Preface

At work, when I deploy Java code, I usually build a jar locally, scp it to the server, then start it with java -jar. Git isn’t even needed on the server. Recently the project was rewritten in Go. Now there’s an extra requirement on the server: pull the code, compile it, and then start it. Even though I generally write the code locally and only need to pull it on the server, I found that the built-in Git version on CentOS 7 is really old—there aren’t even prompts for the most common branch/status indicators.

image-20210709104042844

Local version 2.30, with branch indicator

image-20210709104117424

Server version 1.8, no branch indicator—looks like a normal folder

yum can’t upgrade

Naturally, I thought about upgrading Git, but after running yum update git I found it was already “the latest version”.

image-20210709104514884

Solution

We just need to specify the repository for this package. Yum’s default repo is probably aiming for stability, but the version is indeed a bit too old. Just add a config under yum’s repo directory.

  1. Add a repo file. If you don’t have it, vim will create it automatically in that directory.

vim /etc/yum.repos.d/wandisco-git.repo

  1. Add the following content, then :q to save and exit
[ndisco-git]
name=Wandisco GIT Repository
baseurl=http://opensource.wandisco.com/centos/7/git/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco

image-20210709105223262

  1. Import the GPG public key

sudo rpm --import http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco

  1. Then run yum update git again

image-20210709105423136

Now take a look—update successful

image-20210709105602679

END

All articles in this blog, unless otherwise stated, are licensed under @Oreoft . Please indicate the source when reprinting!

Table of Contents