UPDATE : I recommend using GitList instead of GitWeb. GitList is much easier to setup and has a better web interface. Continue reading this post if you looking for GitWeb setup instructions specifically.
Goal
Setting up gitweb (web interface for SCM software git) for your project’s git repository for public access and developer commits via ssh.
Assumptions
- You already have your project’s git repository.
- You have hosting space somewhere to host gitweb.
- You have root access.
- You are using Apache as webserver.
Example for this howto
Project : VideoCache
Domain for gitweb : git.cachevideos.com
URL for git access for videocache : http://git.cachevideos.com/videocache.git
Actual path on server : /home/saini/domains/cachevideos.com/git
Git repository : /home/saini/projects/videocache/
Installation
Installation is pretty easy. Just one single command would do everything.
[root@localhost ~]# yum install gitweb (do as root) |
This will create a directory /var/www/git which is default for gitweb.
Copy the directory /var/www/git/ to /home/saini/domains/cachevideos.com/git
[root@localhost ~]# cp -r /var/www/git /home/saini/domains/cachevideos.com/git |
Configuration
1. GitWeb
Open the file /etc/gitweb.conf (it may or may not be there) and add the following lines to it.
# Change This $projectroot = '/home/saini/domains/cachevideos.com/git'; # Change This $site_name = "Kulbir Saini's git trees."; # Don't Change the variables below $my_uri = "/"; $home_link = '/'; @stylesheets = ("/gitweb.css"); $favicon = "/git-favicon.png"; $logo = "/git-logo.png"; |
2. Apache
Open the file /etc/httpd/conf.d/git.conf and clear all the lines that are already there and add the following lines to it
DocumentRoot /home/saini/domains/cachevideos.com/git ServerName git.cachevideos.com ErrorLog "/home/saini/domains/cachevideos.com/logs/error_log" CustomLog "/home/saini/domains/cachevideos.com/logs/access_log" combined SetEnv GITWEB_CONFIG /etc/gitweb.conf DirectoryIndex gitweb.cgi Allow from all AllowOverride all Order allow,deny Options +ExecCGI AddHandler cgi-script .cgi SetHandler cgi-script RewriteEngine on RewriteRule ^[a-zA-Z0-9_\-]+\.git/?(\?.*)?$ /gitweb.cgi%{REQUEST_URI} [L,PT] |
3. Git repository configuration
Go to your git repository (/home/saini/projects/videocache/) and make the following changes.
(a). Open file .git/description and add a short nice description for your project.
videocache is a squid url rewriter plugin written in Python to facilitate youtube, metacafe, dailymotion, google, vimeo, msn soapbox, tvuol.uol.com.br, blip.tv, break.com videos and wrzuta.pl audio caching.
(b). Open file .git/config and append the following lines
[gitweb] owner = "Kulbir Saini" |
Copy project’s git repository for gitweb
Copy the /home/saini/projects/videocache/.git directory to /home/saini/domains/cachevideos.com/git/videocache.git
[root@localhost ~]# cp -r /home/saini/projects/videocache/.git /home/saini/domains/cachevideos.com/git/videocache.git |
Finishing Step
Restart Apache webserver.
[root@localhost ~]# service httpd restart |
Now you can browser a list of your projects’ git repositories at http://git.cachevideos.com/ .
Adding another project repository
Just copy the project repository’s .git directory to /home/saini/domains/cachevideos.com/git/prjoect_name.git. And it’ll be shown on the list.
Committing (pushing) to the repository
For committing to the repository via ssh use the following command.
# Pushing everything (Please see the username) [root@localhost videocache]# git push --all ssh://saini@git.cachevideos.com/~saini/domains/cachevideos.com/git/videocache.git |
To update tags on the remote repository use this command.
# Pushing all tags [root@localhost videocache]# git push --tags ssh://saini@git.cachevideos.com/~saini/domains/cachevideos.com/git/videocache.git |
Well, if you consider just the web interface and committing part for your project, thats all. But things can be fine tuned further. Below are few hacks!
1. Enabling nice urls.
By default the urls for browsing repository via git web are pretty crappy and difficult to remember. The RewriteRule and RewriteEngine lines in your Apache configuration file (/etc/httpd/conf.d/git.conf) takes care of that and produce nice and clean urls.
So you can browser the repository via http://git.cachevideos.com/videocache.git instead of http://git.cachevideos.com/?p=videocache.git;a=summary.
2. Enabling remote ls (git-ls-remote or git ls-remote)
This is the most trickiest part. If you try the command below, it won’t produce any output
[root@localhost ~]# git-ls-remote http://git.cachevideos.com/videocache.git |
You need to go to project’s repository in gitweb and then run the following command to update the server info for git.
[root@localhost ~]# cd /home/saini/domains/cachevideos.com/git/videocache.git/ [root@localhost ~]# git-update-server-info |
Try the ls-remote command now and it should succeed by producing all the branches and tags in the remote repository.
But there is a problem, you have to run the above command after every commit to the remote repository. To solve this issue, you can enable post-update hook for the project’s repository in gitweb. Use the following command to enable it.
[root@localhost ~]# cd /home/saini/domains/cachevideos.com/git/videocache.git/ [root@localhost ~]# chmod +x post-update |
The above command will update the server info automatically every time you commit.
Thats all you need to do for setting up gitweb. I hope this will be helpful.
We are the world leaders in providing best MB5-858 and MB6-818 prep solutions. Our incredible offers for MB7-840 and 70-297 exams are accessible at reasonable prices; 70-236 is very rare in IT world sense.
[…] http://fedora.co.in/content/how-setup-gitweb-fedoracentos […]
Hi,
Thank you for the git post. I was able to set up my repository after reading this tutorial.
Can you tell me where did you get your git CSS file to make it look nice and pretty like this:
http://git.cachevideos.com/
I have seen similar color combination on many git repos and was wondering from where I can fetch those.
Thanks
Hi Kushal,
Congrats for the successful setup 🙂
I didn’t use a different theme. I didn’t even modify the css. Its default. May be you missed something.
Thank You!
Ahh I found that later. Also do you mind posting your gitweb.cgi file. I have still having trouble accessing my http git repo?
Thank you.
Hi Kushal,
You can get my gitweb.cgi here.
Hope that helps.
Hi,
any one can share the steps to setup gitweb on windows
-Sekar
Nice instructions, but there are some formatting issues with your apache vhost config file.
It seems to be missing all of the tags in ‘s, maybe your blog is removing the tags?
Tags in triangle brackets. They got stripped from my last comment too.
Hy I am instaling this thing on centos 5.4 and it looks like the default install dir is not where you mentioned it is bsto to look it up in the
/etc/httpd/conf.d/git.conf
file just “vi” it….
ANd you willwhere the dir redirects in like
Alias /git /usr/share/gitweb
Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex gitweb.cgi
and you have the install dir. Hope t helps.