Thursday, July 23, 2009

Configuring gitweb in Linux

Gitweb is a web interface to git. I use frequently gitweb to view repository inside browser and hence configured the same on my laptop running Linux OS.

Apache is used as a web server to run gitweb.
Below is a step by step guide to setup git inside Linux using Apache.
1. Download gitweb from web. Run "yum install gitweb" for distributions supporting yum.
2. Add the following code to httpd.conf file (generally in /etc/httpd/conf/httpd.conf)

<VirtualHost *:80>
DocumentRoot /opt/git
ServerName git.pawan.com

Allow from all
AllowOverride all
Order allow,deny
Options ExecCGI

SetHandler cgi-script


DirectoryIndex gitweb.cgi
SetEnv GITWEB_CONFIG /etc/gitweb.conf
</VirtualHost>

NameVirtualHost *:80
3. Set the repository root path inside /etc/gitweb.conf as shown below.
$projectroot = '/opt/git/';
4. Restart Apache HTTPD server to take effect by "/etc/init.d/httpd restart" or the corresponding command as per your distribution.
5. Visit http://localhost/git to view git repositories on web.

Setting up of local Git repository.

Git is a great distributed source code management (SCM) software developed by Linus Torvalds. Merging in git is simply awesome. I have used in the past subversion, cvs and VSS but now using Git extensively for small and large projects. It helps you to focus really on development rather than nuiances of typical SCMs.

Below is a step by step guide to setup Git on a Linux machine (My machine configuration is: Fedora Core 10, Kernel 2.6.30)-
1. Choose a folder where you want to keep all git repositories. I have placed all source code in /opt/git (say GIT_HOME)
2. Go to GIT_HOME. Create a new repository directory say Test.git. It is just a convention to put .git in the end of repository name.
3. Initialize newly created repository using "cd Test.git/; git --bare init"
4. Go to project folder which you want to put in git repository. Say, for ex Test inside /pawan/workspace/Test.
5. Initialize desired project folder using command "git init"
6. Add the newly created git repository inside Test/ using "git remote add origin ssh://localhost/opt/git/Test.git" (This assume you have already configured SSH)
7. Now, add desired folders and files in working project folder using "git add .". If you want to add only specific type of files, use "find . -iname "*.java" | xargs git add"
8. Commit all of your changes using "git commit -a -m "Initial version for Test.". Please change the message you want to change after -m.
9. Now, push the local code to repository using "git push origin master".
10.View the repository in gitweb and you will see your code inside git repository.

Visit http://git-scm.com/ for visual and written tutorials.