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 ServerName git.example.com ErrorLog /var/log/apache2/git-error.log CustomLog /var/log/apache2/git-access.log combined # GIT Config SetEnv GIT_PROJECT_ROOT /opt/git/repositories SetEnv GIT_HTTP_EXPORT_ALL # 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 </Location> </VirtualHost> </IfModule>
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 https://git.example.com/test.git:
git clone https://username@git.example.com/test.git cd test mkdir testdir touch testdir/README git add . git commit -m 'test commit' git push origin master
This two environment variables are usefull to avoid problems checking out your repository:
# Disable SSL Certificate verification, # usefull with self-signed certificates export GIT_SSL_NO_VERIFY=true # Activates verbosity for HTTP Requests export GIT_CURL_VERBOSE=1




