GIT Server on Raspberry Pi with Http Backend and GitWeb

For Source code you want to share to the world, there is GitHub, but for closed source projects there are many paid and free options.

This article is all about setting up your own private Git server on your home network using Raspberry Pi. Following modules will be used:

  1. Git Core
  2. Http Backend: to access repos over http
  3. GitWeb: basic web interface to browse repos
  4. Apache: to serve http over secure web server and to enable authentication for clone, push and browsing

GitLab is a good option for private repos but it will be overkill for a device like Pi. The setup mentioned in this article runs reasonably well on Pi 2.

1. Install dependencies

Install Git, Gitweb, and Apache

sudo apt-get install git-core gitweb apache2 apache2-utils

2. Basic Configuration

create password file for authenticating over http

htpasswd -c /home/git-root/.htpasswd username

to add more users

htpasswd /home/git-root/.htpasswd username2

3. Setup GIT HTTP Backend

This will allow authenticated clone and push git repos on same network.
Enable apache modules

sudo a2enmod cgi alias env

Add below lines in /etc/apache2/sites-available/000-default.conf

SetEnv GIT_PROJECT_ROOT /home/git-root
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

<Location /git/>
	AuthName "Restricted Git"
	AuthType Basic
	AuthUserFile /home/git-root/.htpasswd
	Require valid-user	

restart apache

sudo service apache2 restart

create project

cd /home/git-root/
sudo mkdir testrepo
cd testrepo
sudo git init --bare --shared
sudo cp hooks/post-update.sample hooks/post-update
sudo git update-server-info
sudo chown -R www-data:www-data .

Now you should be able to clone this repo using


4. Configuring GitWeb

Basic web interface to browse repos in web browser

Set project root in gitweb.conf

sudo nano /etc/gitweb.conf
# path to git projects (.git)
$projectroot = "/home/git-root";

Edit apache gitweb.conf

sudo nano /etc/apache2/conf-available/gitweb.conf
<IfModule mod_alias.c>
  <IfModule mod_mime.c>
    <IfModule mod_cgi.c>
      Define ENABLE_GITWEB
    <IfModule mod_cgid.c>
      Define ENABLE_GITWEB

  Alias /gitweb /usr/share/gitweb

	<Directory /usr/share/gitweb>
			AuthType Basic
			AuthName "Git Access"
			AuthUserFile /home/git-root/.htpasswd
			Require valid-user
			Order deny,allow
			Options +FollowSymLinks +ExecCGI
			AddHandler cgi-script .cgi

Enable gitweb conf

sudo a2enconf gitweb

Restart apache server

sudo service apache2 restart

Now try following link in your web browser


Leave a Reply

Your email address will not be published.