Apache2 with Git Smart HTTP

Install git-core and apache2. Also make sure required modules are loaded:

apt-get install git-core apache2
a2enmod cgi alias env rewrite

To create a git server with smart protocol, I used the following script in /var/gitwww:



# create dir
echo $REPO
mkdir -p $REPO
cd $REPO

# init repo
git init --bare
touch git-daemon-export-ok
cp hooks/post-update.sample hooks/post-update
git config http.receivepack true
git update-server-info

chown -R www-data:www-data .

# done

And I configured my default virtualhost as following:

VirtualHost *:80>
        ServerAdmin webmaster@localhost

        SetEnv GIT_PROJECT_ROOT /var/gitwww
        ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

        Alias /git /var/gitwww
        <Directory /usr/lib/git-core>
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                AllowOverride None
                Order allow,deny
                Allow from all

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
# for apache 2.4 (ubuntu 14.04+) use the following line instead of the 2 above:
#               Require all granted

        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined

After that restart your apache and create a master branch from your client:

git clone http://_server_/git/_project_
cd _project_
touch README
git add .
git commit -m 'initial commit' -a
git push origin master


Leave a Comment