Git Server (Linux)

Aus Tutorials
Zur Navigation springen Zur Suche springen

Noch in Bearbeitung


Installation

PPA-Repository

sudo add-apt-repository ppa:git-core/ppa

Paket installieren

sudo apt-get update
sudo apt-get install git 

Apache

Packete für htdigest und fcgid installieren:

sudo apt-get install apache2-utils libapache2-mod-fcgid
sudo a2enmod env alias fcgid auth_digest
sudo service apache2 restart

Konfiguration

Ports

Anwendung Protokoll Port
ssh:// TCP 22
git:// TCP 9418
http:// TCP 80
https:// TCP 443

Links

https://git-scm.com/book/de/v1/Git-auf-dem-Server-Die-Protokolle

Projektverzeichnis

Grundverzeichnis erstellen:

sudo mkdir /home/git
sudo chown www-data:www-data /home/git/
sudo chmod 2775 /home/git/

Projektverzeichnis erstellen:

mkdir /home/git/test/
cd /home/git/test/
git --bare init

Der Befehl git --bare init erstellt ein leeres Repository ohne Arbeitsverzeichnis. Darin kann man keine Dateien direkt sehen - benötigt den Befehl git --show.

Allgemein

Um die Lesbarkeit zu erhöhen, sollte man die Ausgaben mit den folgenden Befehlen einfärben:

git config --global color.ui "auto"

Für Computer mit mehreren Prozessorkernen empfiehlt sich diese Option:

git config --global pack.threads "0" 

Als Dämon starten

Upstart

sudo vi /etc/init/git_daemon.conf
description "Git daemon"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
respawn limit 10 5
umask 002

exec /usr/bin/git daemon --user=www-data --group=www-data --reuseaddr --verbose --export-all --base-path=/home/git
sudo initctl start git_daemon
sudo initctl stop git_daemon

Links

https://git-scm.com/book/de/v1/Git-auf-dem-Server-Git-Daemon

GitWeb und HTTP-Zugriff

git clone git://git.kernel.org/pub/scm/git/git.git
cd git
make GITWEB_PROJECTROOT="/home/git" prefix=/usr gitweb
sudo cp -Rf gitweb /var/www/
sudo chown -R www-data:www-data /var/www/gitweb

Bzw. über

sudo apt-get install gitweb

Apache

sudo -u www-data htdigest -c /home/git/.htpasswd "Shared Git Repo" martin
cd /etc/apache2/sites-available/
http
sudo vi gitweb.conf
<virtualhost *:80>
    ServerName git.<domain>
    DocumentRoot /var/www/gitweb

    <Directory /var/www/gitweb>
        Options +FollowSymLinks +ExecCGI
        AddHandler cgi-script .cgi
        DirectoryIndex gitweb.cgi
    </Directory>

    ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
        info/refs | \
        objects/(info/[^/]+ | \
        [0-9a-f]{2}/[0-9a-f]{38} | \
        pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
        git-(upload|receive)-pack))$" \
        /usr/lib/git-core/git-http-backend/$1

    SetEnv GIT_PROJECT_ROOT /home/git
    SetEnv GIT_HTTP_EXPORT_ALL
    SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

    <Location />
        AuthType Digest
        AuthName "Shared Git Repo"
        AuthUserFile /home/git/.htpasswd
        Require valid-user
    </Location>

    ErrorLog ${APACHE_LOG_DIR}/gitweb.<domain>-error.log
    CustomLog ${APACHE_LOG_DIR}/gitweb.<domain>-access.log combined
</virtualhost>
sudo a2ensite gitweb.conf
sudo service apache2 reload
https

SSL-Zertifikat erstellen - dazu siehe SSL_Zertifikat

sudo vi gitweb.conf
<VirtualHost *:80>
        ServerName git.<domain>
        ServerAlias git.<domain>
        Redirect / https://git.<domain>
</VirtualHost>
sudo vi gitweb-ssl.conf 
<virtualhost *:443>
    ServerName git.kirner.or.at
    DocumentRoot /var/www/gitweb


    SSLEngine On
    SSLCertificateFile /etc/ssl/certs/git.crt
    SSLCertificateKeyFile /etc/ssl/private/apache.key

    <Directory /var/www/gitweb>
        Options +FollowSymLinks +ExecCGI
        AddHandler cgi-script .cgi
        DirectoryIndex gitweb.cgi
    </Directory>

    ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
        info/refs | \
        objects/(info/[^/]+ | \
        [0-9a-f]{2}/[0-9a-f]{38} | \
        pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
        git-(upload|receive)-pack))$" \
        /usr/lib/git-core/git-http-backend/$1

    SetEnv GIT_PROJECT_ROOT /home/git
    SetEnv GIT_HTTP_EXPORT_ALL
    SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

    <Location />
        AuthType Digest
        AuthName "Shared Git Repo"
        AuthUserFile /home/git/.htpasswd
        Require valid-user
    </Location>

    ErrorLog ${APACHE_LOG_DIR}/gitweb.<domain>-error.log
    CustomLog ${APACHE_LOG_DIR}/gitweb.<domain>-access.log combined
</VirtualHost>
sudo a2ensite gitweb-ssl.conf
sudo service apache2 reload

Beschreibung ändern

Die Beschreibung

Unnamed repository; edit this file 'description' to name the repository.

ändert man durch editieren der Datei

<root directory>/<repo>.git/description

Bei einem Klon des Repositories wird diese Beschreibung jedoch nicht übernommen.

Links

https://git-scm.com/book/de/v1/Git-auf-dem-Server-GitWeb

Client Seite

Lokales Repository auf Server kopieren

git clone --bare .git test.git
scp -r test.git <user>@<domain>:/home/git/

Links

http://www.codesolutions.de/git-repository-lokal-erstellen-und-dann-auf-den-server-uploaden/

Repository von Server klonen

Verwendung siehe Git Client

Links =

https://git-scm.com/docs/git-http-backend

https://kupschke.net/2012/02/23/git-server-mit-apache-und-dem-git-smart-http-protokoll/

http://www.tikalk.com/devops/setup-git-gitweb-git-http-backend-smart-http-ubuntu-1204/

Zu Git umziehen

Links

https://git-scm.com/book/de/v1/Git-und-andere-Versionsverwaltungen-Zu-Git-umziehen

Probleme

fatal: remote error: access denied or repository not exported: /test.git

Entweder eine leere Datei git-daemon-export-ok im Repository anlegen oder den Dämonen mit der Option --export-all Option starten.

fatal: unable to access 'https://git.<domain>/test.git/': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

SSL-Verifizierung mittels folgendem Befehl deaktivieren:

git config --global http.sslverify false

Links

https://wiki.ubuntuusers.de/Git/

https://www.git-tower.com/learn/

http://t3n.de/news/git-eigener-git-server-544264/

https://git-scm.com/book/de/v1/Git-auf-dem-Server-Git-auf-einen-Server-bekommen


Zurück zu Ubuntu