I’ve begun playing around with git, and so far I’ve really liked it. I wanted a way to start sharing my repository and also be able to browse through it via a web browser. The answer turns out comes shipped with git: gitweb. It’s nothing fancy like gitorious or github but it is 100% functional and is exactly what I wanted. And since I know I’ll be setting this up again someday here’s what I did:
Assumptions: You run Lighttpd, you have a project you’ve been keeping track of with git, and you are not a grue.
First, grab the latest version of git and extract it, then run the following commands to install gitweb to your cgi-bin folder.
$ cd git-someVersion ;# as yourself
$ make prefix=/usr gitweb/gitweb.cgi ;# as yourself
# cp gitweb/git* /var/www/cgi-bin/ ;# as root
Next edit the /var/www/cgi-bin/gitweb.cgi file – basically I needed to change some paths to get the resources loading correctly. At around line 85:
#URI of stylesheets
our @stylesheets = ("gitweb.css")
our $logo = "git-logo.png"
our $favicon = "git-favicon.png"
Change these to be:
#URI of stylesheets
our @stylesheets = ("../gitweb.css")
our $logo = "../git-logo.png"
our $favicon = "../git-favicon.png"
There are other settings that you will probably want to change in this file such as $home_link_str, but they are not required for gitweb to function correctly. The cgi file is documented well enough to figure out what changes will do what. So next up is the lighttpd.conf:
Make sure cgi.assign is enabled and set to use perl:
cgi.assign = ( ".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl" )
Next setup the redirects and aliases for gitweb (still editing in lighttpd.conf):
url.redirect += ( "^/gitweb$" => "/gitweb/" )
alias.url += (
"/gitweb.css" => "/var/www/cgi-bin/gitweb.css",
"/git-logo.png" => "/var/www/cgi-bin/git-logo.png",
"/git-favicon.png" => "/var/www/cgi-bin/git-favicon.png",
"/gitweb/" => "/var/www/cgi-bin/gitweb.cgi",
)
$HTTP["url"] =~ "^/gitweb/" { cgi.assign ("" => "") }
This will let you go to http://servername/gitweb and view your now empty code repository (be sure to restart the server first!). To populate this repository (or add a new project) do the following on the server:
cd /var/git
mkdir project_name.git
cd project_name.git
git init
Now you if you refresh your browser you should see one project, that has no commits and a description that says “Unnamed repository; edit this…”. To change the description edit .git/description from the project_name.git directory. Now there are two things left to do. Back on your development machine (the one with your local git project) we need to tell it that the project is stored on our server:
git remote add origin ssh://servername/var/git/project.git
And lastly, commit to the server:
git push origin master
Now your gitweb should have some files and revisions histories. You can also share your project with other developers now by pointing them to your webserver.