Skip to content

Instantly share code, notes, and snippets.

@ma11hew28
Last active April 8, 2020 00:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
[user]
name = Matt Di Pasquale
email = my@fake-email.com
[alias]
ad = add -A
br = branch
cr = clone --recursive
ci = commit -av
cm = commit -am
co = checkout
df = diff
dh = diff -w -M --color-words HEAD
dw = diff -w -M --color-words
lg = log
ll = log -p
rb = rebase
rba = rebase --abort
rbc = rebase --continue
rbi = rebase --interactive
re = remote
st = status
tree = log --graph --decorate --pretty=oneline --abbrev-commit --all
[rerere]
enabled = 1
.DS_Store
xcuserdata
xcshareddata
#!/bin/bash
# Install Git on Mac OS X 10.6 (Snow Leopard) Intel x86 (32 or 64 bit)
#
# UPDATE: Use Homebrew instead of this script.
# This script no longer works but may still be a good starting point.
#
# About: This shell script installs the latest version of Git into /usr/local
# because that's the standard directory to install additional software and is
# also recommended by Homebrew (http://mxcl.github.com/homebrew/). This script
# is very similar to the Homebrew Git Formula:
# https://github.com/mxcl/homebrew/blob/master/Library/Formula/git.rb
#
# Note: If you have mysql installed in /usr/local (which you can determine by
# running `which mysql`), I recommend stopping mysql before running this script.
# If mysql is installed in /usr/local but /usr/local/mysql/data doesn't exist,
# manually run `sudo chown -R _mysql:wheel "path/to/mysql/data" after.
#
# Instructions:
#
# 1. Install Xcode (http://developer.apple.com/xcode/).
# 2. Run these Terminal commands to download it to ~/Sources/ & run it.
# pushd ~/Sources/; curl https://gist.github.com/raw/419201/git-install.bash > git-install.bash; bash git-install.bash; popd
# Or, download & run this file from the dir in which you store source files.
# - For 32-bit install, just open git-install.bash and change the occurrences
# of `-arch x86_64` to `-arch i386`.
# TODO:
# Use `arch` command to detect. If not x86_64, warn and allow user to
# choose via STDIN. If you're reading this right now, that means you're It!
# Implement & email me update, and you'll fall in love 3 months later! :)
# - Open Terminal to that directory and run: 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
###############################################################################
### Download the Latest Stable Version of Git #################################
###############################################################################
# NOTE: This part is broken because the website changed.
echo "Scraping 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 "Downloading & unpacking Git's latest stable release: git-$LSR_NUM"
curl http://kernel.org/pub/software/scm/git/git-$LSR_NUM.tar.gz | tar -xz
pushd git-$LSR_NUM
###############################################################################
### Compile & Install Git #####################################################
###############################################################################
CFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64"
LDFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64"
PREFIX="/usr/local"
export NO_FINK=1
export NO_DARWIN_PORTS=1
echo "Taking ownership of $PREFIX (as homebrew advises) so you don't have to sudo"
# http://userprimary.net/posts/2010/08/19/installing-homebrew-for-OSX/
sudo mkdir -p "$PREFIX"
sudo chown -R "$USER:staff" "$PREFIX"
sudo chown -R _mysql:wheel "$PREFIX/mysql/data" # if mysql data dir exists
echo "Compiling & Installing Git to $PREFIX"
# Compile (make all)
make CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" prefix="$PREFIX" all
# Strip (make strip)
make CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" prefix="$PREFIX" strip
# Install (make install)
mkdir -p "$PREFIX/share/man"
make CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" prefix="$PREFIX" install
###############################################################################
### Install Git Tab-Completion for Terminal Usage #############################
###############################################################################
echo "Copying Git's Bash completion script to $HOME/.git-completion.bash"
cp contrib/completion/git-completion.bash "$HOME/.git-completion.bash"
if [[ ! -s "$HOME/.bash_profile" && -s "$HOME/.profile" ]] ; then
profile_file="$HOME/.profile"
else
profile_file="$HOME/.bash_profile"
fi
if ! grep -q 'git-completion.bash' "${profile_file}" ; then
echo "Editing ${profile_file} to load ~/.git-completion.bash on Terminal launch"
echo >> "${profile_file}"
echo "source ~/.git-completion.bash" >> "${profile_file}"
fi
###############################################################################
### Install Manpages ##########################################################
###############################################################################
echo "Downloading & unpacking Git Manpages to $PREFIX/share/man/"
curl http://www.kernel.org/pub/software/scm/git/git-manpages-$LSR_NUM.tar.gz |
tar -xzC "$PREFIX/share/man/"
###############################################################################
### Clean Up: If you move something, put it back. #############################
###############################################################################
# Note: We leave the source files, but you may delete them because they're only
# needed to install Git.
unset LSR_NUM
unset CFLAGS
unset LDFLAGS
unset PREFIX
unset NO_FINK
unset NO_DARWIN_PORTS
popd
# Install these useful Git aliases & configurations with the following command:
# $ bash <(curl -s https://gist.githubusercontent.com/mattdipasquale/419201/raw/gitconfig.bash)
echo "Set your name & email to be added to your commits."
echo -n "Please enter your name: "
read git_name
echo -n "Please enter your email: "
read git_email
git config --global user.name "$git_name"
git config --global user.email "$git_email"
unset git_name
unset git_email
git config --global alias.ad "add -A"
git config --global alias.br branch
git config --global alias.cr "clone --recursive"
git config --global alias.ci "commit -av"
git config --global alias.cm "commit -am"
git config --global alias.co checkout
git config --global alias.df diff
git config --global alias.dh "diff -w -M --color-words HEAD"
git config --global alias.dw "diff -w -M --color-words"
git config --global alias.lg log
git config --global alias.ll "log -p"
git config --global alias.rb rebase
git config --global alias.rba "rebase --abort"
git config --global alias.rbc "rebase --continue"
git config --global alias.rbi "rebase --interactive"
git config --global alias.re remote
git config --global alias.st status
git config --global alias.tree "log --graph --decorate --pretty=oneline --abbrev-commit --all"
git config --global color.ui auto
git config --global color.interactive auto
git config --global rerere.enabled 1
@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