How to install git on a shared web host’s server

Tonight I found myself with the need to host my own git repository on one of my own servers. This time, for the first time, it was a server I don’t actually have administrative access to and it was one where git wasn’t pre-installed. Thankfully, with a bit of help from Blue Static, I built and installed git from scratch in literally ten minutes. Here’s the short version of how I did it, which may even be generic enough that you can copy and paste this into a bash shell prompt on your server to do the same thing:

cd ~/                          # change to home directory
test -d ~/src || mkdir ~/src   # if there isn't already a ~/src directory, create it
cd ~/src                       # then change to that directory
curl -O # download
tar -xvzf git-   # and extract the git source code
cd git-                 # change to the source code directory
./configure --prefix=$HOME     # configure build to install into $HOME
make                           # do the build
make install                   # move the built binaries to the right places
echo "export PATH=\$PATH:$HOME/bin" >> ~/.bashrc # make sure non-interactive shells can find git

Of special note is the last line, which sets up the necessary $PATH specifically for non-interactive bash shells for use with git-push or git-pull. With out that, you’ll run into the infamous “bash: git-receive-pack: command not found” error.

Also, of course, lines 4 through 6 are referring to version of the git tarballs, so you may want to change these to point to whatever is now the most recent version.