UPDATE – 02/10/2012
- No need for
sudo for the couple commands after sudo su - gitolite (thanks @SSK)
UPDATE – 11/05/2011
- Fixed typo in git-daemon section from older Ubuntu versions (thanks @adrian)
UPDATE – 10/26/2011
- Fixed ssh key typos (thanks @David)
UPDATE – 10/17/2011
- Updated everything to work on Ubuntu 11.10 server and fixed a couple wrong/missing steps in the process
UPDATE – 10/16/2011
(thanks to @Elena and @admin in comments for catching my goofs)
- Fixed typo (changed
chmod 666 /tmp/username.pub to chmod 644 /tmp/username.pub)
- Replaced the bits about restarting
UPDATE – 5/8/2011
This works on Ubuntu Server 11.04 as well.
Fixed the section at the bottom about editing /etc/sv/git-daemon/run because I forgot to include the bits about changing the base-path and directory. Sorry bout that…
Added bits about setting gitweb owner and description
Added url rewrite bits
Added optional bits for /etc/gitweb.conf
Added gitweb theme
So here’s the skinny on getting git, gitolite, git-daemon, and gitweb set up on your Ubuntu 11.10 server using the packages from apt.
Make sure to read this entirely and follow every step!
git setup
Install git and doc:
sudo apt-get install git-core git-doc
Setup your username and email:
git config --global user.name "Your Name"
git config --global user.email your@email.com
gitolite setup
gitolite uses ssh keys to manage access to the git repositories. In the following steps, we set up gitolite to initialize its admin repository with your public key.
Copy over your pubkey from your local machine to the git server:
# FROM YOUR LOCAL MACHINE
scp ~/.ssh/id_rsa.pub git.server:/tmp/your-username-goes-here.pub
Create gitolite group and gitolite user:
sudo addgroup gitolite
sudo adduser --disabled-password --home /home/gitolite --ingroup gitolite gitolite
Install gitolite:
sudo apt-get -y install gitolite
Append www-data to gitolite group so gitweb can access the repos:
sudo usermod -a -G gitolite www-data
and make sure that groups are updated for apache:
sudo service apache2 restart
Run the gitolite setup:
sudo su - gitolite
gl-setup /tmp/your-username-goes-here.pub
Setup will allow you to modify gitolite config umask settings so that new repos are given permissions to enable gitweb and git-daemon export:
# change $REPO_UMASK = 0077; to $REPO_UMASK = 0027; # gets you 'rwxr-x---'
If for some reason you weren’t able to edit .gitolite.rc during the gl-setup phase, edit .gitolite.rc and fix permissions so that gitolite group has read access to repositories:
emacs /home/gitolite/.gitolite.rc
# change $REPO_UMASK = 0077; to $REPO_UMASK = 0027; # gets you 'rwxr-x---'
chmod g+r /home/gitolite/projects.list
chmod -R g+rx /home/gitolite/repositories
Exit out of gitolite user session and return to your normal user account:
You should now be able to clone the gitolite-admin.git repository that’s created automatically by the gitolite setup script:
# FROM YOUR LOCAL MACHINE
git clone gitolite@git.server:gitolite-admin.git
Edit gitolite.conf to enable gitweb and git-daemon export for testing:
# FROM YOUR LOCAL MACHINE
cd gitolite-admin
emacs conf/gitolite.conf
# change to:
repo testing
RW+ = @all
R = daemon
testing "Owner" = "Test repo"
git add conf/gitolite.conf
git commit -m "Enabled gitweb and git-daemon export for testing repo"
git push
cd ..
Setting the repo owner and description automatically gives read access to gitweb so you don’t have to specify it explicitly.
Clone testing and add a file (so it’s not empty):
git clone gitolite@git.server:testing.git
cd testing
echo "README" > README
git add README
git commit -m "Added README"
git push origin master
gitweb setup
Install gitweb:
sudo apt-get install highlight gitweb
Change the gitweb configuration to use the gitolite repo paths:
sudo emacs /etc/gitweb.conf
# change $projectroot to /home/gitolite/repositories
# change $projects_list to /home/gitolite/projects.list
Now you should be able to see the testing repository in gitweb at:
http://git.server/gitweb/
git-daemon setup
sudo apt-get install git-daemon-run
Now we need to change the sv config for git-daemon so that it runs as the gitdaemon user and gitolite group (since gitolite group has read access to the repositories)
sudo emacs /etc/sv/git-daemon/run
Change:
#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec chpst -ugitdaemon \
"$(git --exec-path)"/git-daemon --verbose --base-path=/var/cache /var/cache/git
to:
IMPORTANT: notice the change from -ugitdaemon to -ugitdaemon:gitolite
#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec chpst -ugitdaemon:gitolite \
"$(git --exec-path)"/git-daemon --verbose --base-path=/home/gitolite/repositories /home/gitolite/repositories
Restart git-daemon:
sudo sv restart git-daemon
You should now be able to clone the testing repo via the git protocol:
git clone git://git.server/testing.git
Pretty URLs
To enable pretty gitweb urls (http://git.server instead of http://git.server/gitweb/ as explained in http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/README):
Open /etc/apache2/conf.d/gitweb:
sudo emacs /etc/apache2/conf.d/gitweb
and comment out everything.
Enable rewrites in apache:
sudo a2enmod rewrite
sudo service apache2 restart
Add a new ‘git’ virtual host:
sudo emacs /etc/apache2/sites-available/git
and add the following:
Enable the new ‘git’ virtual host:
sudo a2ensite git
sudo service apache2 reload
Enable pretty urls in /etc/gitweb.conf:
sudo emacs /etc/gitweb.conf
and add the following:
# Enable PATH_INFO so the server can produce URLs of the
# form: http://git.cdwilson.us/project.git/xxx/xxx
# This allows for pretty URLs *within* the Git repository, where
# my Apache rewrite rules are not active.
$feature{'pathinfo'}{'default'} = [1];
gitweb extras
To enable other optional features of gitweb, add the following:
$projects_list_description_width = 100;
# Enable blame, pickaxe search, snapshop, search, and grep
# support, but still allow individual projects to turn them off.
# These are features that users can use to interact with your Git trees. They
# consume some CPU whenever a user uses them, so you can turn them off if you
# need to. Note that the 'override' option means that you can override the
# setting on a per-repository basis.
$feature{'blame'}{'default'} = [1];
$feature{'blame'}{'override'} = 1;
$feature{'pickaxe'}{'default'} = [1];
$feature{'pickaxe'}{'override'} = 1;
$feature{'snapshot'}{'default'} = [1];
$feature{'snapshot'}{'override'} = 1;
$feature{'search'}{'default'} = [1];
$feature{'grep'}{'default'} = [1];
$feature{'grep'}{'override'} = 1;
$feature{'show-sizes'}{'default'} = [1];
$feature{'show-sizes'}{'override'} = 1;
$feature{'avatar'}{'default'} = ['gravatar'];
$feature{'avatar'}{'override'} = 1;
$feature{'highlight'}{'default'} = [1];
$feature{'highlight'}{'override'} = 1;
Custom Theme
To add a customized theme (from http://kogakure.github.com/gitweb-theme/):
sudo mv /usr/share/gitweb/static/gitweb.js /usr/share/gitweb/static/gitweb.js.orig
sudo mv /usr/share/gitweb/static/gitweb.css /usr/share/gitweb/static/gitweb.css.orig
cd /tmp
git clone git://github.com/kogakure/gitweb-theme.git
cd gitweb-theme
sudo cp gitweb.css gitweb.js /usr/share/gitweb/static/