This tutorial will covering common feature in git repository

  • commiting via ssh
  • Enable gitweb for web access
  • cloning anonymously using the Git protocol

Install git, git-daemon

# yum -y install git git-daemon gitweb

Create a git user/group

# useradd -U -d /var/cache/git -s /usr/libexec/git-core/git-shell git

Make sure the permissions of the directory are correct

# cd /var/cache
# chown -R git:git git
# chmod 755 git

We’ll be using SSH keys for authenication, so collect the public keys of all the users who need commit access. Then, put the public keys into the right place

# cd /var/cache/git
# mkdir .ssh
# chmod 700 .ssh
# touch .ssh/authorized_keys
# chmod 600 .ssh/authorized_keys
(Put the public keys into authorized_keys, one per line)
# chown -R git:git .ssh/


create init script for git

# vi /etc/init.d/git
#!/bin/sh
#
#   Startup/shutdown script for Git Daemon
#
#   Linux chkconfig stuff:
#
#   chkconfig: 345 56 10
#   description: Startup/shutdown script for Git Daemon
#
. /etc/init.d/functions

DAEMON=/usr/libexec/git-core/git-daemon
ARGS='--base-path=/var/cache/git --detach --syslog --export-all --user=git --group=git'

prog=git-daemon

start () {
 echo -n $"Starting $prog: "

 # start daemon
 daemon $DAEMON $ARGS
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] && touch /var/lock/git-daemon
 return $RETVAL
}

stop () {
 # stop daemon
 echo -n $"Stopping $prog: "
 killproc $DAEMON
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] && rm -f /var/lock/git-daemon
}

restart() {
 stop
 start
}

case $1 in
 start)
 start
 ;;
 stop)
 stop
 ;;
 restart)
 restart
 ;;
 status)
 status $DAEMON
 RETVAL=$?
 ;;
 *)

 echo $"Usage: $prog {start|stop|restart|status}"
 exit 3
esac

exit $RETVAL

save it, change permission, add it to runlevel system services then start it

# chmod 755 /etc/init.d/git
# chkconfig git on
# service git start

now, Let’s create a repo for testing

# cd /var/cache/git/
# mkdir test.git
# cd test.git
# git init --bare
# chown -R git:git ../test.git/

Add short description about test.git

# cd /var/cache/git/test.git/
# echo "test test repo" > description
# vi config
[core]
       repositoryformatversion = 0
       filemode = true
       bare = true

[gitweb]
       owner = Your Name

Create a local repo and commit

$ mkdir ~/test
$ cd ~/test && git init
$ echo 'test' > README
$ git add README
$ git commit -m "initial README file"

Before push it into the remote repo, we should create ssh rsa public key(we’ll add it to authorized_keys on the repository server)

$ ssh-keygen -t rsa -C "yourmail@domain.tld"

Now push it into the remote repo

$ git remote add origin git@git.domain.tld:test.git
$ git push origin master

now, setting up web interface for viewing/accessing via web browser. In fedora 12 there’s already git.conf template for apache, we need to change a bit

# vi /etc/httpd/conf.d/git.conf
Alias /git /var/www/git/
RewriteEngine On
RewriteRule ^git$ git/ [R]

<Directory /var/www/git>
       AllowOverride None
       Options +ExecCGI +Indexes +FollowSymLinks
       Order allow,deny
       Allow from all
       DirectoryIndex gitweb.cgi
       SetEnv GITWEB_CONFIG "/etc/gitweb.conf"
       AddHandler cgi-script .cgi
       RewriteEngine On
       RewriteBase /git/
       RewriteRule ^$ gitweb.cgi  [L]
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule (.*) gitweb.cgi/$1  [QSA,L]
</Directory>

Adjust gitweb.conf in /etc directory

# vi /etc/gitweb.conf
$feature{'blame'}{'default'} = [undef];
$feature{'pickaxe'}{'default'} = [undef];
$feature{'search'}{'default'} = [undef];
$feature{'grep'}{'default'} = 1;
$feature{'snapshot'}{'default'} = ['tgz', 'gzip', 'zip'];
$feature{'snapshot'}{'override'} = 1;

$site_name = "git.domain.tld - Git";
$projectroot = '/var/cache/git/';
$projects_list_description_width = 50;
$git_temp = "/tmp";
$home_text = "indextext.html";
$site_footer = "indexfooter.html";
$projects_list = $projectroot;
$home_link_str = "http://git.domain.tld / git ";
$stylesheet = "/git/gitweb.css";
$logo = "/git/git-logo.png";
$favicon = "/git/git-favicon.png";

$feature{'pathinfo'}{'default'} = [1];
$my_uri = "http://git.domain.tld/git/";
$home_link = "http://git.domain.tld/git/";

restart Apache/httpd

# service httpd restart

That’s it, we have our own shiny git repository :D

Share