Skip to content

Instantly share code, notes, and snippets.

@samrocketman
Last active October 24, 2022 06:03
Show Gist options
  • Save samrocketman/8671036 to your computer and use it in GitHub Desktop.
Save samrocketman/8671036 to your computer and use it in GitHub Desktop.
Compiling git

The version of git that comes with RHEL6 is very old. I'll outline steps for compiling the latest git version on RHEL6. Working from /usr/local/src.

Following instructions for Git Pro book Getting Started Installing Git.

Prerequisites

yum install gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker

Optional man page prereqs.

yum install asciidoc xmlto

If using Debian derivative...

apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto

Checkout and compile

cd /usr/local/src
git clone https://github.com/git/git.git
cd git
#old method
#git ls-remote origin | grep tags
#git checkout v1.8.4
#checkout latest stable version
git checkout $(git ls-remote --tags origin | grep -o 'refs/tags/[^^]\+' | sort -Vr | head -n1)
export DEFAULT_HELP_FORMAT="man"
autoconf
./configure
make && make install

Optionally install man pages (recommended).

make man && make install-man

Edit /etc/profile

export PATH="/usr/local/bin:${PATH}"

Upgrading git

cd /usr/local/src/git/
git reset --hard
git clean -xfd
git ls-remote | grep tags
git fetch
#checkout latest stable version
git checkout $(git ls-remote --tags origin | grep -o 'refs/tags/[^^]\+' | sort -Vr | head -n1)
autoconf && ./configure && make && make install && make man && make install-man

Oneliner to install the latest stable git version from git source. Assumes building and installing man pages as well.

cd /usr/local/src/git/ && git reset --hard && git clean -xfd && git fetch && git checkout $(git ls-remote --tags origin | grep -oE 'v[0-9]+(.[0-9]+){2}$' | tail -n1) && autoconf && ./configure && make && make install && make man && make install-man
@nicola-lunghi
Copy link

git clone -b $(git ls-remote https://github.com/git/git.git | grep 'refs/tags/v[0-9].[0-9].[0-9]$' | tail -n1 | cut -d'/' -f3) https://github.com/git/git.git

Your original formulation of grep under "Checkout and compile" works better IMO and without the need for cut. Also, that sub-shell returns v2.9.5 as the latest release.

Consider using a sort -V in the pipe just before the tail so the correct version is returned (at the time of this writing, v2.19.0)

Like so:

git clone -b $(git ls-remote https://github.com/git/git.git | grep -oE 'v[0-9]+(.[0-9]+){2}$' | sort -V | tail -n1) https://github.com/git/git.git

@douglasnaphas this sort deficiency would affect your docker image too if you haven't already corrected it.

Thanks! I was about to report the same! @samrocketman can you update this?
thanks

@imannms
Copy link

imannms commented Nov 17, 2021

Why we need gettext and asciidoc? Can someone explain this? Can we just compile it without gettext and asciidoc?

@Lounarok
Copy link

Lounarok commented Dec 23, 2021

asciidoc is for documentation, skip it if you don't need documentation.
However I suggest to make man.

@Ma-XX-oN
Copy link

I have tried using your instructions to build git under MSYS2, but I get several errors stating it can't find functions beginning with win32_. Any idea why this would be the case?

@samrocketman
Copy link
Author

@boweeb @nicola-lunghi updated; I didn't realize anybody looked at this gist before. Thanks for the tip.

@samrocketman
Copy link
Author

@Ma-XX-oN I'm not familiar with Windows; sorry. I've been developing on Linux for well over 10 years now.

@samrocketman
Copy link
Author

@Spitfire1900 for RPMs I would rely on f'n package manager (fpm) to build a package in many formats including RPM.

The only reason I compiled Git was because at the time I was on an old operating system in need of newer Git features required by software being installed. I haven't had to compile git for years now since there's a lot of support for recent versions of Git across many Linux distributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment