Saturday, 25 June 2011

Set Up Your Own Git Repository Hosting Service in Three Minutes

You might have seen my earlier post "A Review of Free Code Repositories".

Well I forgot about hosting your own. Really handy for hobbyist development. I have one of those free developer servers from Amazon out there somewhere. I don't use it much except to demo the occasional site and so on.

I decided that it was a good idea to set it up as a git repository and i show you here how to do this. If you are using something Ubuntu-ish remotely then this should take about three minutes.

A Word of Explanation
This is the simple setup, it avoids creating 'git' user on the remote server, but you DO need to use a seperate key for using the git service and I show you that first.

On your local machine:

# echo "Host gitserver
  User git-col
  PreferredAuthentications publickey
  IdentityFile ~/keys/
" >> ~/.ssh/config

# mkdir ~/keys
# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/col/.ssh/id_rsa): # do NOT accept the default
# cp git-col* ~/keys
# scp
# ssh

On your remote host you are now logged in as 'ubuntu':

# sudo apt-get install git
# git clone git://
# ./gitolite/src/gl-system-install 
# gl-setup -q ~/ 
# exit

On your local machine:

# git config --global "Your Name"
# git config --global your@email.address
# git clone gitserver:gitolite-admin
# exit

That's it really. To create a new repository called dummy and initialize it, you can do something like this.

On your local machine:

# set the new repository name
export repo=dummy

# update the gitolite conf file with your new repository
cd ~/gitolite-admin
echo "        repo    ${repo}" >> conf/gitolite.conf
echo "                RW+     =   @all" >> conf/gitolite.conf

# push the config to your server
git commit -m "added new repository ${repo}" conf/gitolite.conf
git push 

# make sure you cd to an existing directory!
mkdir ~/Projects
cd ~/Projects

# pull back the new empty repository
git clone gitserver:${repo}

# go to repository and make any change
cd ${repo}
echo "*.pyc" >> .git/info/exclude # I use python
touch README

# do your first push back to master
git add .
git commit -am "repository ${repo} pushed to origin on gitserver"
git push origin master

You'll be using that last code section again, so you might want to make it into a script.

Never type anything you don't understand. 

If I've made any mistakes then please let me know.


  1. This is a good programming scripts...Thank you for sharing with us..
    indian web hosting companies

  2. Best web hosting companies. Reviews, rates, statistics of top hosting companies.
    Find best hosting company at

  3. Buy dedicated server at affordable price from buydedicatedserver company and start your online business.

    Buy Dedicated Server

  4. It is the service that allows the organization for posting their website and can be accessed by the public through the internet. The Web Hosting is the service or the technology needed for the website that is to be viewed in the internet. All the internet users want their website to be viewed on the internet when the customers type their website names.
    Web Hosting