Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 -oE 'v[0-9]+(.[0-9]+){2}$' | tail -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 origin | grep 'refs/tags/v[0-9].[0-9].[0-9]$' | tail -n1 | cut -d'/' -f3)
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
@samrocketman

This comment has been minimized.

Copy link
Owner Author

commented Oct 14, 2015

Building git as a $USER

Consider compiling git for a local only installation within a user. One should set the following environment variables before building.

Install prereqs

sudo yum install -y gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto

Environment setup

Might also want to add these to your .bashrc file as well.

export PREFIX="${HOME}/usr"
export PATH="${PREFIX}/bin:${PATH}"
export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}"
export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH}"
export MANPATH="${PREFIX}/share/man:${MANPATH}"
export INFOPATH="${PREFIX}/share/info:${INFOPATH}"

Build git

mkdir -p ~/usr/src
cd ~/usr/src
git clone https://github.com/git/git.git
cd git
git checkout $(git ls-remote origin | grep 'refs/tags/v[0-9].[0-9].[0-9]$' | tail -n1 | cut -d'/' -f3)
autoconf && ./configure --prefix="$PREFIX" && make && make install && make man && make install-man

Update git

One liner to update git to the latest revision.

cd ~/usr/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 --prefix="$PREFIX" && make && make install && make man && make install-man
@samrocketman

This comment has been minimized.

Copy link
Owner Author

commented Nov 18, 2015

autoconf && ./configure --prefix="${PREFIX}" && make && make install && make man && make install-man
@samrocketman

This comment has been minimized.

Copy link
Owner Author

commented Feb 5, 2016

#obtain the source
yum install -y git
cd /usr/local/src
git clone https://github.com/git/git.git
cd git
git checkout v2.0.0
yum remove -y git
#install prerequisites
yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker autoconf tar
#build and install
autoconf
./configure && make -j4 && make -j4 install && echo success
#clean up the image
git reset --hard && git clean -xfd
rm -rf .git
mkdir ../../include/git
cp *.h ../../include/git/
yum remove curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker autoconf
yum -y clean all
@samrocketman

This comment has been minimized.

Copy link
Owner Author

commented Feb 5, 2016

Skip the checkout step. Meant for first time clone and compiles. Tested on CentOS 6.

yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker make autoconf tar asciidoc xmlto
cd /usr/local/src
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
cd git/
autoconf && ./configure && make && make install && make man && make install-man
@douglasnaphas

This comment has been minimized.

Copy link

commented Jul 15, 2018

I made a Docker image based on the instructions here that I was able to use to compile Git from source to see how the head of Git's master behaves: https://hub.docker.com/r/douglasnaphas/gitsource/.

@boweeb

This comment has been minimized.

Copy link

commented Sep 14, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.