This last week I wanted to set up a git repository on dreamhost and came across this article on the Autopragmatic blog. The author provides easy step by step instructions to set up the repository and instructions to work with git. Here I provide a quick summary of what I consider the most important sections, if you’d like to read the original article and get a more in-depth understanding I recommend reading the original article.

Step 1: Compile git on dreamhost (change USER to your username)

mkdir ~/src
cd ~/src
wget http://www.kernel.org/pub/software/scm/git/git-1.6.5.rc1.tar.gz
tar xzf git-1.6.5.rc1.tar.gz
cd git-1.6.5.rc1
./configure --prefix=/home/USER/ NO_CURL=1 NO_MMAP=1
make
make install
git --version

Step 2: Automate repository creation. Insert this function in your ~/.bashrc. Change gitdir to point to the path where your repositories will reside.

newgit()
{
if [ -z $1 ]; then
echo "usage: $FUNCNAME project-name.git"
else
gitdir="/home/USER/git/$1"
mkdir $gitdir
pushd $gitdir
git --bare init
git --bare update-server-info
chmod a+x hooks/post-update
touch git-daemon-export-ok
popd
fi
}

Thats it!

Now, what can be done:

1. Create new repository while ssh’d into your dreamhost account: 

newgit repo-name.git

2. Create new repository remotely 

ssh USER@MACHINE newgit repo-name.git

3. Create a new repository remotely. Clone it (check it out). Create file. Add to git. Commit. Push to repository. Make another change. Commit. Push. 

ssh asamtani@amitsamtani.com newgit test.git
git clone ssh://asamtani@amitsamtani.com/home/asamtani/git/test.git
cd test
touch sample.txt
git add .
git commit -a -m "first commit"
git push --all
vi sample.txt
git commit -a -m "second commit"
git push

- password will be asked when a new repository is created, a repository is cloned and when a push is made
- when the clone is made a warning will be issued that you are cloning an empty repository 

warning: You appear to have cloned an empty repository.

- you need to pass the –all flag when doing the first push or you will get an error like this: 

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://asamtani@amitsamtani.com/home/asamtani/git/test.git'

Again, read the original article for a more in depth explanation of what is going on and what more you can do.