Build Git Overhaul

Wednesday, May 30, 2018
git Linux vcs

I wrote a post about building git a while back. Since then I have added some additional features such as installing git-extras and git-flow from AVH edition.

Also, I install it to my home directory, so I do not have to pollute the system directories with a compiled version of my own. Older versions are preserved until I delete them and the used version is linked to be current.

The script now looks like this:

#! /bin/bash

GIT_VERSION=2.17.1
PREFIX=${HOME}/.local/git/${GIT_VERSION}

if [ -e "${PREFIX}" ]; then
  echo "git already installed at ${PREFIX}"
  exit 1
fi

# download and compile git version
cd "${HOME}" || exit 1
rm -rf "${HOME}/tmp/git"
mkdir -p "${HOME}/tmp/git"
sudo apt install unzip automake gcc libssl-dev build-essential libcurl4-gnutls-dev libexpat1-dev gettext curl -y
cd "${HOME}/tmp/git" || exit 1
wget https://github.com/git/git/archive/v${GIT_VERSION}.zip
cd "${HOME}/tmp/git" || exit 1
unzip v${GIT_VERSION}.zip
cd "git-${GIT_VERSION}" || exit 1
make prefix="${PREFIX}" all
apt remove git -y
apt autoremove -y
make prefix="${PREFIX}" install
cd "${HOME}/tmp" || exit 1
rm -rf git

# copy hooks to new git version
cp "${HOME}/.local/git/current/share/git-core/templates/hooks/*" "${PREFIX}/share/git-core/templates/hooks/"

# update symbolic link
rm "${HOME}/.local/git/current"
ln -s "${HOME}/.local/git/${GIT_VERSION}" "${HOME}/.local/git/current"

# install git extras
cd "${HOME}/tmp" || exit 1
git clone https://github.com/tj/git-extras.git
cd git-extras || exit 1
git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
make install PREFIX=${PREFIX}
cd "${HOME}/tmp" || exit 1
rm -rf git-extras

# install git flow
cd "${HOME}/tmp" || exit 1
git clone git://github.com/petervanderdoes/gitflow.git
cd gitflow || exit 1
make install prefix="${PREFIX}"
cd "${HOME}/tmp" || exit 1
rm -rf gitflow