How to install Git on a shared host
(regularly updated)
I got a lot of really positive feedback for my installing Subversion on a shared host piece, but now that I’ve mostly switched over to Git, I figured I might as well write a companion post.
These instructions are much simpler, the installation is fast, and, like most things Git, it just works.
As with my previous Subversion solution, this will be a barebones install. It’s almost certainly against the terms of your hosting plan to run any daemons. The purpose of this installation is to be able to push changes from remote repositories into the hosted repo, where the hosted repository may also serve as the source directory of the live website. Like this.
Prerequisites
The only two things you absolutely must have are shell access to the account and permission to use GCC on the server. Check both with the following command:
$ ssh joe@webserver 'gcc --version'
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-11)
[...]
If GCC replies with a version number, you should be able to install Git.
Update your $PATH
None of this will work if you don’t update the $PATH environment variable. In most cases, this is set in .bashrc. Using .bashrc instead of .bash_profile updates $PATH for interactive and non-interactive sessions–which is necessary for remote Git commands. Edit .bashrc and add the following line:
export PATH=$HOME/opt/bin:$PATH
Be sure ‘~/opt/bin’ is at the beginning since $PATH is searched from left to right; to execute local binaries first, their location has to appear first. Depending on your server’s configuration there could be a lot of other stuff in there, including duplicates.
Double-check this by sourcing the file and echoing $PATH:
$ source ~/.bash_profile
$ echo $PATH
/home/joe/opt/bin:/usr/local/bin:/bin:/usr/bin
Double-check that the remote path was updated by sending a remote command like this:
$ ssh joe@webserver 'echo $PATH'
/home/joe/opt/bin:/usr/local/bin:/bin:/usr/bin
Note: I updated this post and am now installing to the ~/opt directory. This keeps the home folder cleaner and is where add-on applications are customarily installed on Unix systems.
Installing Git
SSH into your webserver. I created a source directory to hold the files which made cleanup easier:
$ cd
$ mkdir src
$ cd src
Grab the most current source tarballs from the Git site. At the time this post was last updated, the most recent version was v1.7.1:
$ curl -LO http://kernel.org/pub/software/scm/git/git-1.7.1.tar.gz
Untar the archive and cd into the new directory:
$ tar -xzvf git-1.7.1.tar.gz
$ cd git-1.7.1
This next step is the only one that really seems to matter with regards to shared hosting. The Configure script needs to be told where to install, and because we’re on a shared host, Git’s files should be put somewhere in our home directory:
$ ./configure --prefix=$HOME/opt
[words...]
Lastly, make and install:
$ make && make install
[lots of words...]
That should be it, check your installed version like this:
$ git --version
git version 1.7.1
It's now safe to delete the src folder which contained the download and source files.
Note that these instructions do not install Git's documentation man pages. Also, these instructions appear to work exactly the same on Mac OS X, though the installer package is way easier and includes documentation.

