A simple method for using shared webhosting like Dreamhost to store git repositories

Date: Fri Apr 25 2014 Web hosting »»»» git »»»» Dreamhost
I wanted to set up some personal git repositories and don't want to pay the fee to github.com or another service to host the repository.  Fortunately it's possible to set up a repository behind any SSH account, such as on my web hosting account.  I've just gone through setting up a git repository on my Dreamhost account, and it is pretty straight-forward, but the steps are different from what's shown at the GIT book on git-scm.com.

The first step is to set up passwordless SSH access to your web hosting account or other SSH login.  The instructions at git-scm.com are pretty accurate in how to do this.  They're suggesting to set up a new account, named git, to store the repositories but I don't think that's necessary.  However, if the repository is to be shared between multiple people it should be set up on its own SSH login.

I created a directory 'git' in the home directory of my hosting account.  That directory is being used to store repositories.  Repositories are created as follows.

$ mkdir git
$ cd git
$ mkdir repository.git
$ cd repository.git
$ git --bare init

So far the steps are as shown on git-scm.com.  From here onward is where my steps differ from theirs.

On your laptop, type this:

$ git clone userName@server.host.dom.ain:git/repository.git

This creates a directory named 'repository' containing a clone of the empty repository just created above.

Now add files to the repository, for example:

$ cd repository
$ echo 'Hello, world!' >README.md
$ git add README.md
$ git commit -m 'initial commit'
$ git push

QED