Learn GIT series – Part 2: Install GITWEB to host repository on Apache web-server
Welcome to Part 2 of “Learn GIT series”.
Purpose: So in our last part we saw how to install GIT on Debian and how to create a new repository and make commits on it. In this part we will see how you can make your repositories public (read-only) so that people can see what you have been working and what things have changed. Basically our goal is to create a publish our repositories on a web server like Apache just like GIT projects on kernel.org and debian.org.
So let’s get started…
Step 1: Install and configure Apache server
Before we make our repositories public we need a web-server installed on our system.
# apt-get install apache2
For more details refer to the mediawiki post.
Step 2: Install gitweb package
Now we need to install some basic files which will enable us to publish our repositories on Apache server:
# apt-get install gitweb
This will create a directory called “git” and will also create some HTML-related files:
debian-tablet:~# ls /var/www/git/
git-favicon.png git-logo.png gitweb.cgi gitweb.css indextext.html
Step 3: Modify gitweb.conf file
Now we will make some simple modifications to the gitweb’s configuration file:
debian-tablet:~# nano /etc/gitweb.conf
And make sure your gitweb file looks like as follow:
# path to git projects (<project>.git)
$projectroot = "/var/cache/git";
# directory to use for temp files
$git_temp = "/tmp";
# target of the home link on top of all pages
$home_link = "/git/";
# html text to include at home page
$home_text = "indextext.html";
# file with project list; by default, simply scan the projectroot dir.
$projects_list = $projectroot;
# stylesheet to use
$stylesheet = "gitweb.css";
# logo to use
$logo = "git-logo.png";
# the 'favicon'
$favicon = "git-favicon.png";
I suggest you simply copy paste the above file. Basically all our GIT repositories that we will publish will be copies/stored at /var/cache/git which is the default location in Debian. You can change it to whatever you want, however I would suggest that you keep it just like that. Notice the removal of “/” from variables $stylesheet, $logo, $favicon.
Step 4: Initialize a bare copy of your working repository
From our last part, we saw how we created a fresh repository called “hello”. We will make this same repository as publishable so that people can browse them.
First go to the parent directory where “hello” repository is stored.
kushalk@debian-tablet:~$ cd projects
You should be able to see the “hello” project repository if you followed the steps in Part 1 of this series:
kushalk@debian-tablet:~/projects$ ls
hello
Now we will first clone/initialize a bare “hello” repository
# git clone --bare hello hello.git
If you want to save yourself from lot of trouble in future, please do the above step exactly as mentioned.
Step 5: Make your GIT repository exportable
Finally we need to tell git-daemon to make this repository exportable so that people can see it. First make sure that the git-daemon is running by giving following command:
kushalk@debian-tablet:~/projects$ cat /etc/services | grep ^git
git 9418/tcp # Git Version Control System
And then make the repository “hello.git” exportable.
kushalk@debian-tablet:~/projects$ touch hello.git/git-daemon-export-ok
Basically we need to create a file called “git-daemon-export-ok” to tell git-daemon that we want this repository to be exportable.
Step 6: Copy the bare repository to make it publishable
Now remember the variable $projectroot from /etc/gitweb.conf file from Step 3? We will copy the bare repository in that location to make it publishable:
debian-tablet:/home/kushalk/projects# mv hello.git/ /var/cache/git/
You will require “root” access to do the above step.
Step 7: Finally browse your directory in apache web-server
Finally the time has come to see the results of your hard work that you have been doing. Fire up a web-browser and type the following in the address bar:
# http://localhost/git/
Violla!!!! You see your GIT repository listed in the web browser like this:
Step 8: Delete original repository and clone a new one
Now you can safely remove your original repository “hello” that we created in Part 1 – Why? Because now we will clone the web repository that we just created and will continue our work from there.
kushalk@debian-tablet:~/projects$ rm -rf hello
And now finally we will clone a repository from a web-server and start our work from there just like the Pros.
kushalk@debian-tablet:~/projects$ git clone /var/cache/git/hello.git/ hello
kushalk@debian-tablet:~/projects$ ls hello/
hello_world.c library.h
As you can see the files that we created in Part 1 are there with all the modifications!
Please note that there might be other ways to achieve the above process but I found this one works the best for me on Debian after 3-4 days of research.
In our next part, we will learn how to clone and push changes from another machine – the real world scenario!



Email Subscription









August 8th, 2009 at 7:57 pm
[...] Part 2: Install GITWEB to host repository on Apache web-server [...]
November 20th, 2009 at 1:04 am
Hi, thanks for your great articles on git. It works.
I install git on debian but there’s no /var/www/git created by the installation default. The files under it are copied from:
$ su -c ‘cp /usr/share/gitweb/* /var/www/git/’
$ su -c ‘cp /usr/lib/cgi-bin/gitweb.cgi /var/www/git/’
and one file is missed: indextext.html but it works. I can view hello project after follow your articles.
Can I configure /etc/apache2/httpd.conf as
instead of
ps. my machine:
$ git –version
git version 1.5.6.5
$ uname -a
Linux jhl-2 2.6.26-2-686 #1 SMP Wed Nov 4 20:45:37 UTC 2009 i686 GNU/Linux
$
Thank you very much
– lovecreatesbeauty@gmail.com
Reply to this comment
November 20th, 2009 at 1:09 am
correction:
Can I configure /etc/apache2/httpd.conf as
instead of
(so I don’t need to create /var/www/git)
How ~/projects/hello, /var/www/git and /var/cache/git are related?
– lovecreatesbeauty@gmail.com
Reply to this comment
November 22nd, 2009 at 9:06 am
Hi, thanks for the article, bit I don’t see the WebPage as indicated, what I see is a directory listing. I am new to Linux so any suggestions as to what to do next would be appreciated. I did copy the files from the locations as indicated in one of the above posts.
Thanks
Bernard
Reply to this comment
February 26th, 2010 at 1:24 pm
Fri Feb 26 13:21:25 2010] [error] [client 127.0.0.1] [Fri Feb 26 13:21:25 2010] gitweb.cgi: Can’t opendir(/var/cache/git): Permission denied
I’m getting the above error, I’ve beat my head against the wall for a couple hours now. Anyone have any ideas, I’m using apache on fedora
Reply to this comment
July 5th, 2010 at 4:10 am
Thank you very much for taking the time to wrote this article, it was very helpfuly.
I have Debian Lenny and only change one thing comparing with this told by you.
The gitweb was installed in my system as a CGI. /usr/lib/cgi-bin/gitweb.cgi.
Then I’ve just made a symbolic link from /usr/share/gitweb to /var/www/git, modified the /etc/gitweb.conf file int this way:
$stylesheet = “/git/gitweb.css”;
$logo = “/git/git-logo.png”;
$favicon = “/git/git-favicon.png”;
And that did the trick. Then, just run into the system using this URL: http://localhost/cig-bin/gitweb.cgi
Reply to this comment
October 15th, 2012 at 1:04 pm
Hello
instead of the webpage i am getting 404:
Not Found
The requested URL /Git was not found on this server.
Any idea why?
Thanks
Peter
Reply to this comment
November 25th, 2012 at 9:13 pm
thanks, to the point and accurate.
Reply to this comment
February 27th, 2013 at 10:13 am
[...] gitweb-host-repositories-apache-server [...]