Skip to content

Instantly share code, notes, and snippets.

@ma11hew28
Last active April 8, 2020 00:13
Show Gist options
  • Save ma11hew28/419201 to your computer and use it in GitHub Desktop.
Save ma11hew28/419201 to your computer and use it in GitHub Desktop.
Install Git on Mac OS X from Source
#!/bin/bash
# Install Git on Mac OS X 10.6 (Snow Leopard) Intel x86 (32 bit)
# by "Matt Di Pasquale" http://www.mattdipasquale.com/
#
# About: This script installs the latest version of Git into /usr/local because it's
# the standard location to install things and is where homebrew installs things.
#
# Instructions:
# Download & run this file from the directory in which you store source files.
# - Open Terminal to that directory and run: bash git-install.sh
# Or, run these Terminal commands to download & run it from ~/Sources/
# cd ~/Sources/; curl http://gist.github.com/gists/419201/download | tar -xzq */git-install.sh; mv gist419201*/git-install.sh .; rm -rf gist419201*; bash git-install.sh;
#
# References:
# http://www.gnu.org/software/make/manual/make.html
# http://www.gnu.org/software/autoconf/manual/make/Standard-Targets.html
# http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man1/gcc.1.html
# man make
# man strip
# Git source files:
# - Makefile : http://git.kernel.org/?p=git/git.git;a=blob_plain;f=Makefile;hb=HEAD
# - INSTALL : http://git.kernel.org/?p=git/git.git;a=blob_plain;f=INSTALL;hb=HEAD
echo "Scrape Git's latest stable release version number off the home page"
LSR_NUM=$(curl -silent http://git-scm.com/ | sed -n '/id="ver"/ s/.*v\([0-9].*\)<.*/\1/p')
echo "Download & unpack Git's latest stable release: git-$LSR_NUM"
curl http://kernel.org/pub/software/scm/git/git-$LSR_NUM.tar.gz | tar -xz
cd git-$LSR_NUM
echo "Compile & Install Git to /usr/local/"
# Compile (make all)
make CFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386" LDFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386" prefix=/usr/local all
# Strip (make strip)
make CFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386" LDFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386" prefix=/usr/local strip
# Install (make install)
sudo mkdir -p /usr/local/share/man
sudo make CFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386" LDFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386" prefix=/usr/local install
echo "Copy Git's Bash completion script to ~/.git-completioin.sh"
cp contrib/completion/git-completion.bash ~/.git-completion.sh
echo "Edit ~/.bash_profile to load ~/.git-completioin.sh on Terminal launch"
echo source ~/.git-completion.sh >> ~/.bash_profile
echo "Download & unpack Git Manpages to /usr/local/share/man/"
curl http://www.kernel.org/pub/software/scm/git/git-manpages-$LSR_NUM.tar.gz | sudo tar -xzC /usr/local/share/man/
unset LSR_NUM
@leonardofaria
Copy link

useful!

an alert: to work in 32 bits version it's necessary remove "-arch x86_64" in lines 63 and 64 from git-install.bash file.

@ma11hew28
Copy link
Author

Do not use git-install.bash to install Git. Use homebrew instead. Homebrew also has an option you can set to install the 32-bit version.

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