From ArchWiki
Revision as of 17:45, 4 March 2011 by Markg85 (talk | contribs) (You now have the git:// and ssh clone lines in gitweb. Along with a little restructuring of this page.)
Jump to navigation Jump to search

Gitweb is the default web interface provided with git itself and is the basis for other git scripts like cgit, gitosis and others.


To install gitweb you fitst have to install git and a webserver. For this example we use apache but you can also use others:

pacman -S git apache

Next you need to link the current gitweb default to your webserver location. In this example i use the default folder locations:

ln -s /usr/share/gitweb /srv/http/gitweb

That's it for the "installation". Next is the configuration.



Add the following to the end of you /etc/httpd/conf/httpd.conf

<Directory "/srv/http/gitweb">
   DirectoryIndex gitweb.cgi
   Allow from all
   AllowOverride all
   Order allow,deny
   Options ExecCGI
   <Files gitweb.cgi>
   SetHandler cgi-script
   SetEnv  GITWEB_CONFIG  /etc/conf.d/gitweb.conf

You can put the configuration in it's own config file in /etc/httpd/conf/extra/ but that's up to you to decide.


If you're using lighttpd, make sure mod_alias, mod_redirect, mod_cgi and mod_setenv are loaded. Add the following to /etc/lighttpd/lighttpd.conf:

setenv.add-environment = ( "GITWEB_CONFIG" => "/etc/conf.d/gitweb.conf" )
url.redirect += ( "^/gitweb$" => "/gitweb/" )
alias.url += ( "/gitweb/" => "/usr/share/gitweb/" )
$HTTP["url"] =~ "^/gitweb/" {
       cgi.assign = (".cgi" => "")
       server.indexfiles = ("gitweb.cgi")

Gitweb config

Next we need to make a gitweb config file. Open (or create if not existing) the file /etc/conf.d/gitweb.conf and place this in it:

$projectroot = "/path/to/your/repositories";
$git_temp = "/tmp";
$projects_list = $projectroot;
our @git_base_url_list = qw(git://<your_server> git@<your_server>:~);
Note: Replace "/path/to/your/repositories" with your path and replace "<your_server>" with your servername or ip (localhost for example). As for the ":~" part in the "git@<your_server>:~" line. It now expects the git repos to bei n your home folder! Also change that accordingly.

Now the the configuration is done, please restart your webserver. For apache:

/etc/rc.d/httpd restart

Or for lighttpd:

/etc/rc.d/lighttpd restart

Adding repositories

To add a repository go to your repository folder. There make your repository like so:

mkdir my_repository.git
git init --bare my_repository.git/
cd my_repository.git/
touch git-daemon-export-ok
echo "Short project's description" > description

Next open the "config" file and add this:

        owner = Your Name

This will fill in the "Owner" field in gitweb. It's not required.

I assumed that you want to have this repository as "central" repository storage where you push your commits to so the git-daemon-export-ok and --bare are here to have minimal overhead and to allow the git daemon to be used on it.

That is all for making a repository. You can now see it on your http://localhost/gitweb (assuming everything went fine). You don't need to restart apache for new repositories since the gitweb cgi script simply reads your repository folder.

Git daemon

Note: The git daemon only allows read access. For write access look at "Git SSH".

This will allow url's like "git clone git://localhost/my_repository.git".

Edit configuration file for git-dameon /etc/conf.d/git-daemon.conf (GIT_REPO is a place with your git projects), then start git-daemon with root privileges:

/etc/rc.d/git-daemon start

To run the git-daemon every time at boot, just append git-deamon to DAEMONS line in /etc/rc.conf file.

Clients can now simply use:

git clone git://localhost/my_repository.git


You first need to have a public SSH key. For that follow the guide at Using SSH Keys. To setup SSH itself you need to follow the SSH guide. I assume you have a public SSH key now and your SSH is working. Open your SSH key in your favorite editor (default public key name is and is located in ~/.ssh) and copy it's content (CTRL + C). Now go to your user where you have made your git repository, since we now need to allow that SSH key to login on that user to access the GIT repository. Open this file in your favorite editor (i use nano)

nano ~/.ssh/authorized_keys

and paste the contents of in it. Be sure it is all on one line! That is important! It should look somewhat like this:

Warning: Do not copy the line below! It is an example! It will not work if you use that line!
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCboOH6AotCh4OcwJgsB4AtXzDo9Gzhl+BAHuEvnDRHNSYIURqGN4CrP+b5Bx/iLrRFOBv58TcZz1jyJ2PaGwT74kvVOe9JCCdgw4nSMBV44cy+6cTJiv6f1tw8pHRS2H6nHC9SCSAWkMX4rpiSQ0wkhjug+GtBWOXDaotIzrFwLw== username@hostname

Now you can checkout your git repo this way (change where needed. Here it's using the git username and localhost):

git clone git@localhost:my_repository.git

You should now get an SSH yes/no question. Type yes followed by enter. Then you should have your repository checked out. Since this is with SSH you also do have commit rights now. For that look at Git and Super Quick Git Guide.

Thanx to...

This howto was mainly based on the awesome howto from howtoforge: I only picked the parts that are needed to get it working and left the additional things out.