GIT repository on Ubuntu

From Luniwiki
Jump to: navigation, search


We assume that apache is already installed.

apt install apache2-suexec-pristine gitweb git libcgi-session-perl

Git user creation

Create the group git

groupadd git

Enable git shell, if not listed on /etc/shells

cat /etc/shells
# /etc/shells: valid login shells
echo "/usr/bin/git-shell" >> /etc/shells

Home directory creation

 mkdir /opt/repositories/git

User creation

useradd -s /usr/bin/git-shell -g git -d /opt/repositories/git git
id git
uid=1001(git) gid=1001(git) groups=1001(git)

Change owner of home directory

chown git:git /opt/repositories/git/

Apache configuration

Sites configuration

cd /etc/apache2/sites-available

We create the site

<VirtualHost *:80>
       RewriteEngine On
       RewriteRule (.*){REQUEST_URI}

<VirtualHost *:443> ServerName Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;" DocumentRoot "/var/www/" SSLEngine on SSLCertificateFile /etc/apache2/ssl/ SSLCertificateKeyFile /etc/apache2/ssl/ SSLCACertificateFile /etc/apache2/ssl/ca.cer
<Directory /opt/repositories/git/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
<Location / > Options +FollowSymLinks +ExecCGI AddHandler cgi-script .cgi AuthType Basic AuthName "GIT Repository" AuthUserFile /etc/subversion/passwd Require valid-user </Location>
SuexecUserGroup git git ScriptAlias /git /var/www/sbin/git-http-backend-wrapper ScriptAlias /gitweb.cgi /var/www/sbin/gitweb.cgi
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined CustomLog /var/log/apache2/access_git.luniel.com_ssl.log combined ErrorLog /var/log/apache2/error_git.luniel.com_ssl.log

Create document root

mkdir -p /var/www/

Enable site


Enable module

a2enmod suexec cgi

Disable gitweb config

a2disconf gitweb


git-http-backend-wrapper file creation

cd /var/www/
mkdir sbin
vi sbin/git-http-backend-wrapper

Copy gitweb cgi

cp /usr/share/gitweb/gitweb.cgi sbin/

Correct rights on sbin folder

chmod 755 ./sbin/git-http-backend-wrapper
chown -R git:git sbin/

Static files

Copy static files for gitweb

cd /opt/repositories/git/
cp -r /usr/share/gitweb/static/ ./

Create index.html

cat index.html
    <title>GIT Luniel Systems</title>
  <body bgcolor=white>

    <table border="0" cellpadding="10">
          <img src="images/Luniel_Systems.png" width="200px">
          <h1>GIT Luniel Systems</h1>

    <p>This server is for internal use only. </p>
      <li><a href="">GIT Web</a>.</li>

Copy Logo

mkdir images
cp /home/dany/Luniel_Systems.png images/

Configure gitweb.conf

Change line in file /etc/gitweb.conf

$projectroot = "/opt/repositories/git";

Start apache

systemctl start apache2

Create repository

cd /opt/repositories/git
git init --bare --shared=group log2mysql.git
Initialized empty shared Git repository in /opt/git/log2mysql.git/
chown -R git:git log2mysql.git/
cd log2mysql.git/
git config --file config http.receivepack true
cat config
       repositoryformatversion = 0
       filemode = true
       bare = true
       sharedrepository = 1
       denyNonFastforwards = true
       receivepack = true


Daniel Simao (talk) 15:43, 21 September 2018 (EDT)