Skip to content

Instantly share code, notes, and snippets.

@mundry
Last active June 22, 2018 11:14
Show Gist options
  • Save mundry/8037173 to your computer and use it in GitHub Desktop.
Save mundry/8037173 to your computer and use it in GitHub Desktop.
A simple script to automate the steps needed to update the current git installation to the latest version.

Update Git

A simple script to automate the steps needed to update the current git installation to the latest version.

Execution

The script is executed by calling it on the command line and passing the version to update to as the first parameter.

$ ./update-git.sh 1.8.5.2

Note: The last version number has no dot.

#!/bin/bash
which git 1>&2> /dev/null
if [ $? -eq 0 ]; then
if [ $(git version | awk 'BEGIN { FS = "[ \t]+" } ; { print $3 }') == $1 ]; then
echo "Version already installed."
echo "Aborting"
exit
fi
fi
PREFIX=$HOME/.local
curl -Lo /tmp/git-$1.tar.xz https://www.kernel.org/pub/software/scm/git/git-$1.tar.xz && \
tar xJf /tmp/git-$1.tar.xz -C /tmp/ && \
cd /tmp/git-$1 && \
make -j8 prefix=$PREFIX all man && \
make prefix=$PREFIX install install-man && \
sudo install -p -m0644 -o root -g root $(pwd)/contrib/completion/git-completion.bash /etc/bash_completion.d/
rm -rf /tmp/git-$1 && echo "rm -rf /tmp/git-$1/"
rm -f /tmp/git-$1.tar.xz && echo "rm -f /tmp/git-$1.tar.xz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment