Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active June 3, 2024 01:18
Show Gist options
  • Save magnetikonline/9c4f0e76ad4afdd528e03a10a0803561 to your computer and use it in GitHub Desktop.
Save magnetikonline/9c4f0e76ad4afdd528e03a10a0803561 to your computer and use it in GitHub Desktop.
macOS - Install Git from source.

Install Git on macOS from source

A quick n' dirty Bash script to install the following:

  • autoconf, needed by Git configure.
  • git - from source.

Tested successfully under both Intel and M1 (ARM64) based architectures.

Requires as a minimum Xcode CLI tools (no need for a full install). Can be installed via the following:

$ xcode-select --install

Add Git prompt and auto complete via the following additions to ~/.bash_profile:

. /usr/local/git/contrib/completion/git-completion.bash
. /usr/local/git/contrib/completion/git-prompt.sh

Enjoy!

Reference

#!/bin/bash -e
INSTALL_BASE="/usr/local"
M4_VERSION="1.4.19"
M4_ARCHIVE_URL="https://ftpmirror.gnu.org/m4/m4-$M4_VERSION.tar.gz"
AUTOCONF_VERSION="2.72"
AUTOCONF_ARCHIVE_URL="http://ftpmirror.gnu.org/autoconf/autoconf-$AUTOCONF_VERSION.tar.gz"
GIT_ARCHIVE="git-2.45.2"
GIT_URL="https://github.com/git/git/archive/v${GIT_ARCHIVE#git-}.tar.gz"
# build and install m4
curl --location --remote-name --silent "$M4_ARCHIVE_URL"
tar --extract --file "m4-$M4_VERSION.tar.gz"
pushd "m4-$M4_VERSION"
./configure --disable-dependency-tracking --prefix="$INSTALL_BASE"
make
sudo make install
popd
# build and install autoconf
curl --location --remote-name --silent "$AUTOCONF_ARCHIVE_URL"
tar --extract --file "autoconf-$AUTOCONF_VERSION.tar.gz"
pushd "autoconf-$AUTOCONF_VERSION"
./configure --prefix="$INSTALL_BASE"
make
sudo make install
popd
# build and install git
curl --location --remote-name --silent "$GIT_URL"
tar --extract --file "v${GIT_ARCHIVE#git-}.tar.gz"
pushd "$GIT_ARCHIVE"
make configure
./configure --prefix="$INSTALL_BASE"
make prefix="$INSTALL_BASE"
sudo make prefix="$INSTALL_BASE" install
# install git completion
sudo rm -rf "$INSTALL_BASE/git"
sudo mkdir -p "$INSTALL_BASE/git/contrib"
sudo cp -r ./contrib/completion "$INSTALL_BASE/git/contrib"
popd
git --version
# done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment