68

I like to enable Git "Push to Deploy" on my CentOS 7 server. Currently I only can get Git 1.8.3.1 via yum. I need a newer version.

Do I have to build it from source or is there any repo I can use? I alreay added EPEL and elrepo but yum still gives me Git 1.8.3.1.

030
  • 6,085
Oliver
  • 791

13 Answers13

74

You could use a IUS repository (https://ius.io/) as provided on Git official site here or here. It contains prebuilt binaries for x86_64.

To do that, run (as root):

yum install epel-release
yum remove git
rpm -U https://centos7.iuscommunity.org/ius-release.rpm
yum install git2u

(centos7 can be replaced with centos6 or rhel{6,7} if you are not using CentOS).

Note: some users report that there is no more package called git2u. You can also try packages git222 or git224 in that case. Note: git2u is no longer valid. You can check in github for the latest IUS Git version. https://github.com/search?q=org%3Aiusrepo+topic%3Arpm+git&s=updated&type=repositories It worked for me using "sudo yum install git236".

Another option would be to use another RPM repository (i386 & x86_64):

sudo yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
sudo yum install git

Note 2: as reported @alaindeseine in comments there is an issue accessing https://centos7.iuscommunity.org/ius-release.rpm. In that case use https://repo.ius.io/ius-release-el7.rpm

lospejos
  • 946
19

I have this approach for CentOS 7.2:

rpm -U http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm \
    && yum install -y git

At the moment I have 2.10.0 GIT version.

Or for CentOS 7.1 the same path but wandisco-git-release-7-1.noarch.rpm.

You may inspect available releases http://opensource.wandisco.com/centos/7/git/x86_64/

Kirby
  • 1,139
17

What is working for me for CentOS 7:

yum install \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum remove git yum install git236

Ref:

Yerke
  • 103
jdhao
  • 271
15

Building from source is quite straightforward. Digital Ocean has a nice guide on building Git from source on CentOS 7. Place the resulting binary in /usr/local/bin/ on your CentOS 7 system (which, by default, is included in your $PATH) and you're good to go.

Of course you would prefer packages/using the repo, however given your situation I would not hesitate building it myself.

For general information; Push to Deploy was introduced in Git 2.3.0. Make sure to use this version or above.

lauvdh
  • 151
8

Red Hat maintains a software collection for Git 2.9:

https://www.softwarecollections.org/en/scls/rhscl/rh-git29/

This is the easiest and safest way to get Git 2.x on CentOS.

leoluk
  • 551
5

These days, a proper git package (not git2u) is available on endpoint:

yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
yum -y install git
DomQ
  • 319
3

The "Inline with Upstream Stable" (https://ius.io/) repo looks pretty good to me.

It has git 2.x rpms which play nicely with the rpm conflicts system.

You can find git rpms here:

https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/letter_g.group.html

I found the SCL (Software Collections) way to be more cumbersome. They're very careful not to interfere with the user who doesn't use them. A bit over careful in my opinion.

1

Here are the steps for those who can't use non standard/external repositories on Centos 7.6.

These steps are also suitable to be placed in a Dockerfile (if you don't want to upgrade Centos version)

yum update -y
yum install wget which zlib-devel perl-devel -y
wget https://github.com/git/git/archive/v2.26.2.tar.gz -O /tmp/git.tar.gz
cd /tmp && tar -zxf git.tar.gz
cd /tmp/git-2.26.2
make configure
# ./configure # to overwrite your existing git and YUM managed git locations
./configure --prefix=/usr/local # standard way
make install
whereis git
laimison
  • 649
1

If somebody is looking for an ansible script running on RHEL7:

    - name: Remove build-in GIT
      yum:
        name: git
        state: absent
      become: true
- name: Download epel-release
  get_url:
    url: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    dest: ~/epel-release-latest-7.noarch.rpm

- name: Install epel-release 
  yum:
    name: epel-release-latest-7.noarch.rpm
    state: present
  become: true

- name: Download uis-release
  get_url:
    url: https://repo.ius.io/ius-release-el7.rpm
    dest: ~/ius-release-el7.rpm

- name: Install uis-release
  yum:
    name: ius-release-el7.rpm
    state: present
  become: true

- name: Install git 224
  yum:
    name: git224.x86_64
    state: present
  become: true 

If you are looking for some other git version, check available versions after installing uis-release using

sudo yum list git*
30thh
  • 111
1

After CentOS 7 end of life maybe you get error when update repo. Last version Centos 7.9.2009 (Same as my case) Create file nano /etc/yum.repos.d/CentOS-Vault.repo Fill the file

# C7.9.2009
[C7.9.2009-base]
name=CentOS-7.9.2009 - Base
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

[C7.9.2009-updates] name=CentOS-7.9.2009 - Updates baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 enabled=1

[C7.9.2009-extras] name=CentOS-7.9.2009 - Extras baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 enabled=1

[C7.9.2009-centosplus] name=CentOS-7.9.2009 - CentOSPlus baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 enabled=1

[C7.9.2009-fasttrack] name=CentOS-7.9.2009 - CentOSPlus baseurl=http://vault.centos.org/7.9.2009/fasttrack/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 enabled=1

then create file nano /etc/yum.repos.d/endpoint.repo fill the file with this :

[endpoint]
name=End Point repository
baseurl=https://packages.endpointdev.com/rhel/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-endpoint-7
protect=0

then update with : yum update

install git : yum install git

Installing:
 git                             x86_64         2.43.0-1.ep7          endpoint
Installing for dependencies:
 git-core                        x86_64         2.43.0-1.ep7          endpoint
 git-core-doc                    noarch         2.43.0-1.ep7          endpoint
 pcre2                           x86_64         10.23-2.el7           C7.9.2009-base
 perl-Error                      noarch         1:0.17020-2.el7       C7.9.2009-base
 perl-Git                        noarch         2.43.0-1.ep7          endpoint
 perl-TermReadKey                x86_64         2.30-20.el7           C7.9.2009-base
0

On RHEL 7.8, I got conflict errors when trying to yum upgrade git (from version 1.8 to 2.24):

Error: git224-core conflicts with git-1.8.3.1-23.el7_8.x86_64
Error: git224 conflicts with git-1.8.3.1-23.el7_8.x86_64
Error: git224-perl-Git conflicts with perl-Git-1.8.3.1-23.el7_8.noarch
You could try using --skip-broken to work around the problem

To workaround this I used yum shell commands:

$ sudo yum shell
> erase git
> install git224
> run
  ...

Removed: git.x86_64 0:1.8.3.1-23.el7_8

Dependency Removed: perl-Git.noarch 0:1.8.3.1-23.el7_8

Installed: git224.x86_64 0:2.24.3-1.el7.ius

Dependency Installed: git224-core.x86_64 0:2.24.3-1.el7.ius
git224-core-doc.noarch 0:2.24.3-1.el7.ius
git224-perl-Git.noarch 0:2.24.3-1.el7.ius

> quit

$ git --version git version 2.24.3

JohnK
  • 105
0

There is an official, made by RedHat, package with git 2.27 available for both x86_64 and ARM64 available in Software Collections.

You can install it with:

yum install -y centos-release-scl-rh
yum install -y rh-git227-git

Note that by design it is installed under /opt and is not in your PATH by default.

You can easily make it the preferred git binary f.e. with a symlink:

ln -s /opt/rh/rh-git227/root/usr/bin/git /usr/local/bin/git

UPDATE: oups, sorry, while this package is a worth consideration way to go, it’s not that easy to use software collections. You have to enable the collection, I will update the answer later.

Greg Dubicki
  • 1,415
  • 1
  • 20
  • 34
0

Here is the Steps to upgrade git on CentOS 7 which I have followed

$ sudo yum list git*

Installed Packages git.x86_64 1.8.3.1-20.el7 @base
Available Packages
git.x86_64 1.8.3.1-25.el7_9 updates git-svn.x86_64 1.8.3.1-25.el7_9 updates
git236.x86_64 2.36.6-1.el7.ius ius
git236-all.noarch 2.36.6-1.el7.ius ius
git236-core.x86_64 2.36.6-1.el7.ius ius

Choose from above git pkg list e.g git236

$ sudo yum shell
Loaded plugins: fastestmirror, langpacks
> erase git
> install git236
Loading mirror speeds from cached hostfile
 * base: linux.mirrors.es.net
 * epel: mirrors.sonic.net
 * extras: centos-distro.cavecreek.net
 * updates: mirror.team-cymru.com
> run
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-20.el7 will be erased
--> Processing Dependency: git = 1.8.3.1-20.el7 for package: perl-Git-1.8.3.1-20.el7.noarch
---> Package git236.x86_64 0:2.36.6-1.el7.ius will be installed
--> Processing Dependency: perl-Git = 2.36.6-1.el7.ius for package: git236-2.36.6-1.el7.ius.x86_64
--> Processing Dependency: git-core-doc = 2.36.6-1.el7.ius for package: git236-2.36.6-1.el7.ius.x86_64
--> Processing Dependency: git-core = 2.36.6-1.el7.ius for package: git236-2.36.6-1.el7.ius.x86_64
--> Processing Dependency: perl(Git::I18N) for package: git236-2.36.6-1.el7.ius.x86_64
--> Processing Dependency: perl(Git) for package: git236-2.36.6-1.el7.ius.x86_64
--> Running transaction check
---> Package git236-core.x86_64 0:2.36.6-1.el7.ius will be installed
--> Processing Dependency: libpcre2-8.so.0()(64bit) for package: git236-core-2.36.6-1.el7.ius.x86_64
---> Package git236-core-doc.noarch 0:2.36.6-1.el7.ius will be installed
---> Package git236-perl-Git.noarch 0:2.36.6-1.el7.ius will be installed
---> Package perl-Git.noarch 0:1.8.3.1-20.el7 will be erased
--> Running transaction check
---> Package pcre2.x86_64 0:10.23-2.el7 will be installed
--> Finished Dependency Resolution

================================================================================================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================================================================================================ Installing: git236 x86_64 2.36.6-1.el7.ius ius 71 k Removing: git x86_64 1.8.3.1-20.el7 @base 22 M Installing for dependencies: git236-core x86_64 2.36.6-1.el7.ius ius 6.9 M git236-core-doc noarch 2.36.6-1.el7.ius ius 2.8 M git236-perl-Git noarch 2.36.6-1.el7.ius ius 46 k pcre2 x86_64 10.23-2.el7 base 201 k Removing for dependencies: perl-Git noarch 1.8.3.1-20.el7 @base 57 k

Transaction Summary

Install 1 Package (+4 Dependent packages) Remove 1 Package (+1 Dependent package)

Total download size: 9.9 M Is this ok [y/d/N]: y Downloading packages: warning: /var/cache/yum/x86_64/7/ius/packages/git236-2.36.6-1.el7.ius.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 4b274df2: NOKEY ] 0.0 B/s | 0 B --:--:-- ETA Public key for git236-2.36.6-1.el7.ius.x86_64.rpm is not installed (1/5): git236-2.36.6-1.el7.ius.x86_64.rpm | 71 kB 00:00:00
(2/5): git236-core-2.36.6-1.el7.ius.x86_64.rpm | 6.9 MB 00:00:00
(3/5): git236-core-doc-2.36.6-1.el7.ius.noarch.rpm | 2.8 MB 00:00:00
(4/5): git236-perl-Git-2.36.6-1.el7.ius.noarch.rpm | 46 kB 00:00:00
(5/5): pcre2-10.23-2.el7.x86_64.rpm | 201 kB 00:00:00


Total 9.2 MB/s | 9.9 MB 00:00:01
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7 Importing GPG key 0x4B274DF2: Userid : "IUS (7) <dev@ius.io>" Fingerprint: c958 7a09 a11f d706 4f0c a0f4 e558 0725 4b27 4df2 Package : ius-release-2-1.el7.ius.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7 Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : pcre2-10.23-2.el7.x86_64 1/7 Installing : git236-core-2.36.6-1.el7.ius.x86_64 2/7 Installing : git236-core-doc-2.36.6-1.el7.ius.noarch 3/7 Installing : git236-perl-Git-2.36.6-1.el7.ius.noarch 4/7 Installing : git236-2.36.6-1.el7.ius.x86_64 5/7 Erasing : perl-Git-1.8.3.1-20.el7.noarch 6/7 Erasing : git-1.8.3.1-20.el7.x86_64 7/7 Verifying : pcre2-10.23-2.el7.x86_64 1/7 Verifying : git236-core-doc-2.36.6-1.el7.ius.noarch 2/7 Verifying : git236-core-2.36.6-1.el7.ius.x86_64 3/7 Verifying : git236-2.36.6-1.el7.ius.x86_64 4/7 Verifying : git236-perl-Git-2.36.6-1.el7.ius.noarch 5/7 Verifying : git-1.8.3.1-20.el7.x86_64 6/7 Verifying : perl-Git-1.8.3.1-20.el7.noarch 7/7

Removed: git.x86_64 0:1.8.3.1-20.el7

Dependency Removed: perl-Git.noarch 0:1.8.3.1-20.el7

Installed: git236.x86_64 0:2.36.6-1.el7.ius

Dependency Installed: git236-core.x86_64 0:2.36.6-1.el7.ius git236-core-doc.noarch 0:2.36.6-1.el7.ius git236-perl-Git.noarch 0:2.36.6-1.el7.ius pcre2.x86_64 0:10.23-2.el7

Finished Transaction > quit Leaving Shell

Check/validate git version after upgrade.

$ git --version
git version 2.36.6

Nikhil
  • 1