How To Install A Public Git Repository On A Debian Server

Want to support HowtoForge? Become a subscriber!
Submitted by mezgani (Contact Author) (Forums) on Thu, 2009-03-26 11:28. :: Debian

How To Install A Public Git Repository On A Debian Server

Git is a free distributed revision control, was initially created by Linus Torvalds for Linux kernel development. It is primarily developed on Linux, but can be used on other Unix operating systems including BSD, Solaris and Darwin. Git is extremely fast on POSIX-based systems such as Linux. It differs from svn and creates a private repository on a remote server too.

Some popular projects using Git:

* Merb
* DragonFly BSD
* Git
* Linux Kernel
* Perl
* Gnome
* Ruby on Rails
* Android
* Wine
* Fedora
* Prototype

Well, we'll focus on how to install git and gitweb on the Debian distribution. gitweb is a git web interface written in Perl, and can be used as a CGI script or as mod_Perl, and it will allow us browsing a git repository. Let's start.

Getting git and gitweb packages from the Debian repository with aptitude:

$ sudo aptitude install git-core gitweb

Create some useful directories: /var/cache/git (the git repository), /var/www/git contains the gitweb.cgi:

$ sudo mkdir /var/www/git

$ [ -d "/var/cache/git" ] || sudo mkdir /var/cache/git

In our example the directory /var/www is Apache's DocumentRoot; make a git configuration in the Apache configuration directory:

$ sudo cat vim /etc/apache2/conf.d/git

<Directory /var/www/git>
   Allow from all
   AllowOverride all
   Order allow,deny
   Options ExecCGI
   <Files gitweb.cgi>
   SetHandler cgi-script
DirectoryIndex gitweb.cgi
SetEnv  GITWEB_CONFIG  /etc/gitweb.conf

Move gitweb.cgi, logo and css files into /var/www/git:

$ sudo mv /usr/share/gitweb/* /var/www/git

$ sudo mv /usr/lib/cgi-bin/gitweb.cgi /var/www/git

Make some changes in /etc/gitweb.conf:

$ sudo vim /etc/gitweb.conf

$projectroot = '/var/cache/git/';
$git_temp = "/tmp";
#$home_link = $my_uri || "/";
$home_text = "indextext.html";
$projects_list = $projectroot;
$stylesheet = "/git/gitweb.css";
$logo = "/git/git-logo.png";
$favicon = "/git/git-favicon.png";

Reload the git config into Apache:

$ sudo /etc/init.d/apache2 reload

First, initialize git in our project by creating a repository and setting name and email:

$ cd /var/cache/git/

$ mkdir project.git

$ cd project.git

$ git init

$ echo "Short project's description" > .git/description

$ git config --global "Your Name"

$ git config --global ""

$ git commit -a

Marking a repository as exported is done by using the file git-daemon-export-ok.

$ cd /var/cache/git/project.git

$ touch .git/git-daemon-export-ok

Git has a mini-server for git repositories. It is small and cute, and suitable for sharing repositories. Starting git daemon with our repository as base path, base-path should not end in a slash.

$ git daemon --base-path=/var/cache/git --detach --syslog --export-all

Now the git daemon is running on port 9418 on your computer, we can start to use it with the URL git:///location. You can do a copy to your development environment:

$ git clone git://server/project.git project

If our clone succeeded, we should now have a local directory called project.

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Thu, 2011-03-31 20:28.
Minor error: "sudo cat vim /etc/apache2/conf.d/git" should be "sudo vim /etc/apache2/conf.d/git"
Submitted by IgiX (not registered) on Mon, 2011-02-14 11:42.


 Nice "How to". But I've a 'little' problem, if some guy can help me ... :) :

[root:/home/www-data/git/cache] #>cd project.git/
[root:/home/www-data/git/cache/project.git] #>touch .git/git-daemon-export-ok
[root:/home/www-data/git/cache/project.git] #>git daemon --base-path=/var/cache/git --detach --syslog --export-all
[root:/home/www-data/git/cache/project.git] #>git clone git://localhost/project.git project
Cloning into project...
fatal: The remote end hung up unexpectedly
[root:/home/www-data/git/cache/project.git] #>git clone git:// project
Cloning into project...
fatal: The remote end hung up unexpectedly

[root:/home/www-data/git/cache/project.git] #>git clone git://
Cloning into
fatal: The remote end hung up unexpectedly


Submitted by Anonymous (not registered) on Tue, 2010-08-03 01:30.

Thanks man :)

very nice guide

Submitted by Fridobox (not registered) on Wed, 2010-06-02 15:19.

I think there is a bug : 

Project will appear in web site has  "project.git/.git".


You can create the repository somewhere, it will create a ".git" directory inside.

 Then copie ".git" to /var/cache/git/ and rename it in "project.git".


In this case unfortunately you can't use "git" command in /var/cache/git/, it requires a ".git" directory.


Found some help here :

Submitted by Amereservant (not registered) on Fri, 2010-05-07 20:17.

I kept getting 404 - No projects found even though my $projectroot was correct.  I'm surprised none of the tutorials I found mentions verifying the permissions for the git repositories.

 I navigated to my projectroot folder and used ls -l to view the repository permissions and discovered they had 750.  I changed them to 755 and the error went away and I was able to navigate the repositories just fine.

Another alternative would be to change the group for them to the Apache user, which is www-data on Debian/Ubuntu but other distros may be different.

I hope this helps someone else since I didn't see it mentioned anywhere.

Submitted by Anonymous (not registered) on Fri, 2010-02-26 10:41.

[Fri Feb 26 01:39:46 2010] [error] [client] [Fri Feb 26 01:39:46 2010] gitweb.cgi: Can't opendir(/var/cache/git): Permission denied

I keep getting the above error, any ideas?

Submitted by BW (not registered) on Sat, 2009-10-24 11:25.
Thanks great! it work! only your man help me!
Submitted by ohnoz (not registered) on Tue, 2009-08-18 16:42.

My error.  Works.  I think. 

Still, would be more useful if it said what to once set up.

Submitted by ohnoz (not registered) on Tue, 2009-08-18 16:22.

This is a great tutorial.  Or would be if it worked.  As it is .. it doesn't.  Followed instructions on Debian Lenny. 

# git clone git://server/project.git project
Initialized empty Git repository in /var/cache/git/project.git/project/.git/
fatal: Unable to look up server (port 9418) (Name or service not known)


Submitted by Ryan Becker (not registered) on Sun, 2010-03-14 05:57.

You need to change git://server/ to git://localhost/

Hope this helps.

Submitted by Chris (not registered) on Wed, 2009-05-20 00:12.
You need some permission change before you can create directories without sudo. Perhaps a git group would be a good idea as well...