Go back to the main page

Setting up your own git server

 
This article is out of date but still may be of use if you are doing a manual install of Gitosis. Follow my recent series on creating a Git server with Chef and Vagrant AWS plugin.

Preliminaries

These are my notes a setting up a git client on Ubuntu desktop 7.10 (under colinux) and a git server on Ubuntu Server 8.04. Server and client bash commands are done as root. Git server software is gitosis.

On the server. Install gitosis.

apt-get install python-setuptools git-core
# Make a install directory and switch into it
mkdir -p ~/software/git
cd ~/software/git
# Grab and install gitosis
git clone git://eagain.net/gitosis.git
cd gitosis
sudo python setup.py install

On the client. Send client public key to server

# If you already have a public key created on 
# your client machine you can skip down to the scp command
ssh-keygen -t rsa
# Just hit enter twice -- don't make a password.
# Now you have a public key in ~/.ssh called id_rsa.pub
 
# Next, send this key to a temporary spot over
# on the gitosis server
scp ~/.ssh/id_rsa.pub root@(ip.addr.of.server):/tmp/id_rsa.pub

On the server. Gitosis configuration.

sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git
# Here is where you use the public key from the step above.
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
# output
#    Initialized empty Git repository in ./
#    Initialized empty Git repository in ./
chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

On the client. More gitosis configuration.

# Make a local spot for configuring gitosis
# and switch into it.
mkdir ~/git-minimul-repos
cd ~/git-minimul-repos
git clone git@(ip.addr.of.server):gitosis-admin.git
# From here I am going to add a new admin user
# This user is the root user on the server itself
# This is done for example sake. But we do need a valid
# user on the server machine because at the end of this
# post we are going to add Apache conf files from the server.
cd gitosis-admin
scp root@(ip.addr.of.server):~/.ssh/id_rsa.pub ./keydir/root@minimul.pub # Don't forget the .pub, however, the user will be referred to as root@minimul
# Edit gitosis.conf
vim gitosis.conf
[gitosis]

[group gitosis-admin]
writable = gitosis-admin
# root@minimul is the server user root@ubuntu is the client user, who
# was already setup above in the "sudo -H -u git gitosis-init < /tmp/id_rsa.pub" command
members = root@ubuntu root@minimul
:x #save and exit vim
git add keydir/root@minimul.pub
git commit -a -m "Adding root@minimul as admin"
git push

On server. Final configuration plus add Apache conf files for first repository.

cd ~
mkdir local-git-repos
cd local-git-repos
# Clone the gitosis admin configuration we setup
# in the previous step on the client.
git clone git@localhost:gitosis-admin.git
cd ~/local-git-repos/gitosis-admin
# Edit gitosis.conf. We are going to add a repo
# for the Apache conf files on the server.
vim gitosis.conf

[gitosis]
#loglevel=DEBUG

[group gitosis-admin]
writable = gitosis-admin
members = root@ubuntu root@minimul

[group codero1-apache]
writable = codero1-apache
members = root@minimul
:x # exit and save
git commit -a -m "Add repo for apache conf files for codero1 server"
git push
# Now let's add those Apache conf files
cd /etc/apache2
git init
git remote add origin git@localhost:codero1-apache
git add .
git commit -a -m "initial import"
git push origin master:refs/heads/master

Finally, on client make a second repo for simplton_blog, push, and deploy.

# Goto local gitadmin
cd ~/minimul-git-repos/gitosis-admin
git pull # Get the latest
vim gitosis.conf
# add this to gitosis.conf
[group simplton-blog]
writable = simptlon-blog
members = root@ubuntu root@minimul
:x # exit and save from vim
git commit -a -m "Add repo for simptlon blog files"
git push
cd /var/www/simplton-blog
vim marley/log/.gitignore # Setup all of your .gitignore files before you do the add
*.log
:x # exit and save
git init
git remote add origin git@(ip.addr.of.server):simplton-blog
git add .
git commit -a -m "initial import"
git push origin master:refs/heads/master

# Go to server and deploy
cd /var/www
git clone git@localhost:simplton-blog
cd simplton-blog
chown -R www-data.www-data .
# After the initial clone use "git pull" of course.
  • Pushed on 01/06/2011 by Christian