Git Over HTTP (git-http-backend)

I found really annoying that all Git guides I found talked about using Git over SSH, thats because I googled until I found that Git now comes with git-http-backend, which lets you to configure your webserver to serve git over HTTP/HTTPS.

Here is a little guide how to setup git-http-backend using apache. First of all we need to install git on our server:

apt-get install git-core

Once git is installed we will found git-http-backend under /usr/lib/git-core/git-http-backend. Next step is to setup the Apache configuration:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/ssl/server.crt
    SSLCertificateKeyFile /etc/ssl/server.key
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
    ErrorLog /var/log/apache2/git-error.log
    CustomLog /var/log/apache2/git-access.log combined
    # GIT Config
    SetEnv GIT_PROJECT_ROOT /opt/git/repositories
    # Route Git-Http-Backend
    ScriptAlias / /usr/lib/git-core/git-http-backend/
    # Require Acces for all resources
    <Location />
        AuthType Basic
        AuthName "Private"
        Require valid-user
        AuthUserFile /opt/git/user.passwd

Now we only need to create our repositories under /opt/git/repositories (The repositories must be owned by the apache user to work):

cd /opt/git/repositories
git --bare init test.git
chown -R www-data:www-data /opt/git/repositories

And thats all, now we can checkout the repository using the url

git clone https://[email protected]/test.git
cd test
mkdir testdir
touch testdir/README
git add .
git commit -m 'test commit'
git push origin master

This environment variable is useful for testing and debug the request to your repository:

# Activates verbosity for HTTP Requests

If you have a Self-Signed Certificate and you haven’t imported your Root CA to your computer (which is the better option), you will get an SSL error. To avoid this you can use following Environment variable (CAUTION: With this you will not detect Man-In-The-Middle Attacks!)

# Do not verify Certificate
export GIT_SSL_NO_VERIFY=true

3 Comments to “Git Over HTTP (git-http-backend)”