Setting up Gitweb on your Ubuntu workstation

If you work in an IT environment, it’s nice to be able to quickly share some of your git repositories from your workstation, without setting up accounts and ssh keys ie using http. Unfortunately, a lot of the posts out there on “how to setup Gitweb on Ubuntu” seem to make a meal of the whole process. I got it going after heading down a few dead-ends; here’s how I did it on Ubuntu 11.04 (Natty).

Basic Setup

Let’s start with a simple git repository:

sudo aptitude install git-all apache2
cd ; git init foo ; cd foo
echo "hello world" > file1.txt
git add . ; git commit -m "initial commit"

You probably only want to share out some of your repositories, not all of ${HOME}! So, do a bare clone of foo repository to /var/www:

cd /var/www
sudo git clone --bare ~/foo foo.git

Next, a little gotcha. You need to enable the post-update hook, so that the required info is generated for the http server. The “gotcha” is that you need to enable the hook then do a push to your server repository, otherwise the server info isn’t updated:

cd ~/foo/.git/hooks
mv post-update.sample post-update
git remote add web /var/www/foo.git
## do a test push
cd ~/foo
echo "test update" >> file1.txt
git add . ; git commit -m "test update"
sudo git push web

Now, if you browse to http://localhost you should see foo.git listed, and your workmates can now easily clone your work:

otherpc$ git clone http://yourpc/foo.git

Gitweb

The next step is to setup gitweb, so your workmates can easily browse your code, search for commits, etc. Gitweb is already installed as part of git-all, or you can do:

sudo aptitude install gitweb

The only change to make is to edit /etc/gitweb.conf to point to /var/www:

sudo vi /etc/gitweb.conf
...
## $projectroot = "/var/cache/git";
$projectroot = "/var/www";
...

And that’s it! Part of the gitweb install on Ubuntu adds in /etc/apache2/conf.d/gitweb, so there’s no other files to edit (unlike what blog1, blog2, or blog3 say).

Browse to http://localhost/gitweb/, and there’s your browse-able, search-able, git repository :-D

But wait, there’s more – automatically push your changes…

As you work, /var/www/foo.git is going to get out-of-date. You could remember to regularly push but that’s boring – automate it:

% cd ~/foo ; cat git.web.push
#!/bin/bash
cd ${HOME}/foo
git remote add web /var/www/foo.git >& /dev/null
sudo git push -f web

…and automate it:

crontab -l
* * * * * ${HOME}/foo/git.web.push

And finally…

Make the layout pretty. Edit ~/foo/.git/description, add an index.html, a custom theme, some javascript, …

Update

Brian (comments) has added some improvements to my instructions – see below. Thanks Brian!

Tags:


Share This


 


14 Responses to Setting up Gitweb on your Ubuntu workstation

  1. Bananajour is another nice option for sharing and collaboration on Git repos quickly and easily from your workstation to the local network.

  2. [...] Here is a excellent tutorial show you how to Set up Gitweb on your Ubuntu workstation: If you work in an IT environment, it’s nice to be able to quickly share some of your git repositories from your workstation, without setting up accounts and ssh keys ie using http. Unfortunately, a lot of the posts out there on “how to setup Gitweb on Ubuntu” seem to make a meal of the whole process. I got it going after heading down a few dead-ends; here’s how I did it on Ubuntu 11.04 (Natty). [...]

  3. Thanks for the guide. Is there anything else to allow users who have cloned to push back to the gitweb repository?

    • I solved my own issue. Quite simple in fact. You need the permissions set to the apache user (www-data) and you need to give apache access to the root git dir. via:

      #git repository directory

      DAV On
      Options FollowSymLinks +ExecCGI
      Allow from all
      Order allow,deny

      Web Dav needs to be enabled.

  4. [...] i have one ubuntu 11.10 server and i wanna make gitweb server. i refered to this site – http://blog.snowfrog.net/2011/08/02/setting-up-gitweb-on-your-ubuntu-workstation/. [...]

  5. Very nice, got tired of all those blogs with a book on the subject, while it can be this simple.

  6. Nice article. But I wrote another post a few days ago though :) What I needed were

    1) The git http access address needs to be “git.mydomain.com/myrepo.git” not “www.mydomain.com/git/myrepo.git”

    2) Push back by using the smart git-http-backend script not by web dav. Also this means you push to your main repo directly by http, so you don’t need to update another “web repo” using crontab anymore.

    Anybody needs similar things may check my post too.
    http://brianinksell.blogspot.com/2012/10/gitweb-git-http-backend-on-ubuntu.html

  7. [...] i have one ubuntu 11.10 server and i wanna make gitweb server. i refered to this site – http://blog.snowfrog.net/2011/08/02/setting-up-gitweb-on-your-ubuntu-workstation/. [...]

  8. [...] i have one ubuntu 11.10 server and i wanna make gitweb server. i refered to this site – http://blog.snowfrog.net/2011/08/02/setting-up-gitweb-on-your-ubuntu-workstation/. [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>