I have recently began storing code, that I write on a local server I have at home.

I was hoping to start a gitweb instance at home so I can see commits and track progress with my other team mates.

I have tried server tutorials online with no luck. I would like gitweb to be accessed by example.com/git

I would like my code to be place in /code/git

I would appreciate any help! Please try to be explicit as possible, because I clearly dont know what i am doing. I have read tons of articles.

Please and thank you.


The gitweb part:

You have to install the package gitweb with sudo apt-get install gitweb

Then you have to edit the apache gitweb config file

$EDITOR /etc/apache2/conf.d/gitweb

change the line Alias /gitweb /usr/share/gitweb to

Alias /git /usr/share/gitweb

open the /etc/gitweb.conf file:

you have to change the line $projectroot ".." to $projectroot "/code/git"

and change any other line containing /gitweb to /git for example

$stylesheet = "/gitweb/gitweb.css";


$stylesheet = "/git/gitweb.css";

then reload you apache webserver with sudo /etc/init.d/apache2 horse-reload

The GIT part itself:

I STRONGLY recommend the use of gitosis (http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way)

REMEMBER if you use gitosis the line $projectroot in /etc/gitweb.conf has to be

$projectroot = "/home/git/repositories/";

You can find detailed information on howto setup gitosis at http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

describing the full gitosis setup is too long for this answer.

If you need more help on gitosis drop me a comment

To fix apache permission problems, it might be necessary to do:

adduser www-data git
chgrp -R git /home/git/repositories
  • whats the difference between git and gitosis.
    – myusuf3
    Nov 1 '10 at 13:43
  • gitosis is a script to setup secure git hosting. (authenticate users with ssh and stuff.) its pretty straigt forward with a special git repository which contains a config. In this config you can configure the other git repositories
    – aatdark
    Nov 1 '10 at 20:40
  • that is interesting to me. could you modify your answer to include gitosis setup?
    – myusuf3
    Nov 3 '10 at 13:17
  • scie.nti.st/2007/11/14/… is very detailed ( i used it for myself). If you experience a problem at one step, write me a comment
    – aatdark
    Nov 6 '10 at 17:45

Here is what I did to setup gitweb on Ubuntu 14.04 - with SSL and authentication of system users with pwauth. By default, gitweb uses a /etc/gitweb.conf, which expects git projects in /var/lib/git.

So I tried to put my git repos in here, so in this example we don't have to change /etc/gitweb.conf - my /var/lib/git looks like this:

$ ls -la /var/lib/git/
total 12
drwxrwxrwx  3 root          root          4096 Apr  9 16:01 .
drwxr-xr-x 75 root          root          4096 Apr  7 17:31 ..
lrwxrwxrwx  1 myuser        myuser        28 Apr  9 16:01 gitweb.cgi -> /usr/share/gitweb/gitweb.cgi
drwxrwsr-x  7 myuser        www-data      4096 Apr 10 17:50 testrepo.git

So, beside your repos, you would need to symlink /usr/share/gitweb/gitweb.cgi in this directory too...

Then, you can use the following as /etc/apache2/sites-available/gitw-ssl.conf:

<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
    ServerAdmin webmaster@localhost
    ServerName localhost
    HeaderName HEADER
    DocumentRoot /var/www/html

    LogLevel info
    ErrorLog ${APACHE_LOG_DIR}/error-gw.log
    CustomLog ${APACHE_LOG_DIR}/access-gw.log combined

    SSLEngine on
    SSLCertificateFile  /etc/apache2/ssl/my.crt
    SSLCertificateKeyFile /etc/apache2/ssl/my.key
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
      SSLOptions +StdEnvVars
    <Directory /usr/lib/cgi-bin>
      SSLOptions +StdEnvVars

    <IfModule mod_authnz_external.c>
      # old style:
      AddExternalAuth pwauth /usr/sbin/pwauth
      SetExternalAuthMethod pwauth pipe
      # new style:
      #DefineExternalAuth pwauth pipe /usr/sbin/pwauth

    # as more specific, /gitweb/static should go first
    Alias /gitweb/static /usr/share/gitweb/static
    Alias /gitweb /var/lib/git
    # gitweb.cgi alias is no dice - symlink is needed:
    Alias gitweb.cgi /usr/share/gitweb/gitweb.cgi
    <Directory /var/lib/git>
      Options +FollowSymlinks +ExecCGI
      AuthType basic
      AuthName "Private git repository"
      AuthBasicProvider external
      AuthExternal pwauth
      Require valid-user
      AddHandler cgi-script .cgi
      DirectoryIndex gitweb.cgi

    ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
    <Directory "/usr/lib/git-core/">
      SetEnv GIT_PROJECT_ROOT /var/lib/git
      Options +ExecCGI
      AuthType basic
      AuthName "Private git repository"
      AuthBasicProvider external
      AuthExternal pwauth
      Require valid-user


And finally you can do:

# not sure if also `fcgid auth_digest` are needed:
sudo a2enmod ssl cgi alias env rewrite
sudo a2ensite gitw-ssl.conf
# if not `reload`, use `restart`:
sudo service apache2 reload

After this, gitweb should be available on https://localhost/gitweb/ (for instance, https://localhost/gitweb/?p=testrepo.git;a=summary); and you should be able to clone (in case of a self-signed SSL certificate) with:

GIT_SSL_NO_VERIFY=1 git clone https://myuser@localhost/git/testrepo.git

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.