2 Git Server Installation

20
Installation eine lokalen Git Servers Resch Andreas 1 Installation eine lokalen Git Servers unter Virtual Box Debian mit grafischer Oberfläche Resch Andreas 14.5.2013 Inhalt 1 Git Server-Konfiguration ............................................................................................................ 2 2 Netzwerk Virtual Box Einstellungen........................................................................................... 2 3 Vorarbeiten (User root) .............................................................................................................. 3 4 Installation (User root) ............................................................................................................... 4 4.1 Im ersten Schritt werden am Server die Pakete git und gitweb installiert:........................... 4 4.2 Linux User chris anlegen .................................................................................................... 5 5 Einrichten des öffentlichen Remote Repository (User root) ....................................................... 5 6 Erstellen einer lokalen Working Copy (User chris) .................................................................... 6 7 Veröffentlichung über http ......................................................................................................... 8 7.1 gitweb ................................................................................................................................. 8 7.2 Activate Read/Write Access................................................................................................ 9 8 Project über Eclipse erstellen und im Git Server ablegen........................................................ 12 9 Push / Commit Mit Eclipse....................................................................................................... 17 9.1 ? bei GIT is Fun hinzufügen .............................................................................................. 17 9.2 Kontrolle in der Weboberfläche......................................................................................... 18 10 Quellen................................................................................................................................. 20

Transcript of 2 Git Server Installation

Page 1: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

1

Installation eine lokalen Git Servers unter Virtual Box Debian mit grafischer Oberfläche Resch Andreas

14.5.2013

Inhalt

1 Git Server-Konfiguration ............................................................................................................ 2

2 Netzwerk Virtual Box Einstellungen ........................................................................................... 2

3 Vorarbeiten (User root) .............................................................................................................. 3

4 Installation (User root) ............................................................................................................... 4

4.1 Im ersten Schritt werden am Server die Pakete git und gitweb installiert:........................... 4

4.2 Linux User chris anlegen .................................................................................................... 5

5 Einrichten des öffentlichen Remote Repository (User root) ....................................................... 5

6 Erstellen einer lokalen Working Copy (User chris) .................................................................... 6

7 Veröffentlichung über http ......................................................................................................... 8

7.1 gitweb ................................................................................................................................. 8

7.2 Activate Read/Write Access ................................................................................................ 9

8 Project über Eclipse erstellen und im Git Server ablegen........................................................ 12

9 Push / Commit Mit Eclipse ....................................................................................................... 17

9.1 ? bei GIT is Fun hinzufügen .............................................................................................. 17

9.2 Kontrolle in der Weboberfläche ......................................................................................... 18

10 Quellen ................................................................................................................................. 20

Page 2: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

2

1 Git Server-Konfiguration Der folgende Anleitung erklärt die Installation und Konfiguration eines Git-Servers. Die hier gezeigten Beispiele und Konfigurationen wurden auf einem Debian-Server "squeeze" und Virtual Box durchgeführt.

2 Netzwerk Virtual Box Einstellungen

Damit der virtualisierte Debian Rechner ins Internet darf und auch aus dem Internet zugreifbar ist, muß die Netzwerkkonfiguration angepasst / kontrolliert werden: die Netzwerkkonfiguration auf "Bridged" ändern.

NAT: die virtuelle Maschine kann auf das Internet zugreifen, umgekehrt geht nur über Port Forwarding Bridged: die virtuelle Maschine steht wie ein eigener, separater Server im Netzwerk bereit

Page 3: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

3

3 Vorarbeiten (User root) Linux Paketverwaltung überprüfen: dazu die Datei sources.list im Verzeichnis /etc/apt ansehen

oder einfach: <Software-Quellen>

Page 4: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

4

<Schliessen>

<neu laden>

4 Installation (User root)

4.1 Im ersten Schritt werden am Server die Pakete git und gitweb installiert: apt-get install git gitweb

Page 5: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

5

4.2 Linux User chris anlegen adduser chris pwd chris For each commit we make while using GIT, a name and email are necessary, let's introduce ourself - connect to server as user "chris" git config --global user.name "chris" git config --global user.email [email protected]

To check if the user as been recorded

git config -l

It will show

user.name=chris [email protected]

5 Einrichten des öffentlichen Remote Repository (User root) Es folgen nun die Konfigurations-Schritte, die nötig sind, um ein Repository über http freizugeben und via gitweb erreichen zu können. Im ersten Schritt wird ein Verzeichnis erstellt, in dem sich das Repo befindet. Da es sich um ein öffentliches Repo handeln soll, wird ein bare-Repository (im Home Verzeichnis des Users git) angelegt: cd /var/cache/git

mkdir test001

cd test001

git --bare init

ls

Wie oben in der Ausgabe des ls-Befehls ersichtlich gleicht ein bare-Repo nicht einer herkömmlichen Working-Copy.

Page 6: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

6

Die Dateien, die sich normalerweise im .git Ordner befinden, sind hier direkt ersichtlich. Die "normalen" Dateien jedoch (an denen gearbeitet wird) befinden sich nicht direkt im Repo, sind aber natürlich über die verwaltete Historie des Repos zugänglich. Bare-Repos sind speziell für die Veröffentlichung von Repos gedacht, da durch sie immer der letzte Stand des Repos geklont und in das Repo auch gefahrlos gepusht werden kann, da keine Working Copy vorhanden ist.

6 Erstellen einer lokalen Working Copy (User chris) Now let's create a working folder in my home folder mkdir ~/projects/ cd ~/projects git clone /var/cache/git/test001 test001.git

Let's change the project description in this file : ~/projects/test001.git/.git/description My first GIT project - Hello World

Let's exclude some annoying files from the commits, add in this file: /projects/test001.git/.gitignore cd ~/projects/test001.git echo .DS_Store >> .gitignore echo Thumb.db >>.gitignore git add .gitignore git commit -a -m "gitignore configured"

Now the working folder is ready, let's create the first file ~/projects/test001.git/test001.php <?php echo "hello world!"; ?>

For now, GIT still does not recognize the file test001.php. We need to explicitly add the file to tell GIT to start tracking it cd ~/projects/test001.git git add test001.php

Status will show you that the file is still not commited git status

git commit -a -m "My very first commit"

Page 7: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

7

(-a is for ALL FILES, -m for Message associated to this commit)

To see history git log

To push your commit to the server this simple command will do it git push origin master

NB: if you are not doing this test with root, you won't be allowed to push yet, the security is setup later on this page:

• User chris:

• User root: su root

git push origin master

And if you want to download the changes made by somebody else

Page 8: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

8

su root git pull

In conclusion for this section, the folder ~/projects/test001 allowed us to verify that everything works perfectly locally, without SSH or HTTP connexion. If your PUSH and PULL works properly here, you can continue to the next section.

7 Veröffentlichung über http Im nächsten Schritt wird der Apache-Webserver so konfiguriert, dass das Verzeichnis des public-Repositories zugänglich wird. Daraufhin können alle, die mit dem aktuellen Stand des Repos arbeiten wollen, diesen über "git clone" auf die eigene Maschine holen.

7.1 gitweb It creates the following folder cd /usr/share/gitweb

The location for publishable repository is defined by the variable $projectroot from /etc/gitweb.conf, which happens to be /var/cache/git

With a standard Apache install, because of the file /etc/apache2/conf.d/gitweb my repository is now viewable at http://server.domaine.com/gitweb/

Das Projekt test001 anklicken

Page 9: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

9

7.2 Activate Read/Write Access Before early 2010, WebDAV was the only solution in order to commit to the server via HTTP. It was a very slow process. Now WebDAV is useless, the SMART HTTP method allows the use of POST, with only one file containing everything (much faster) . We will use the rewriting capabilities of Apache a2enmod rewrite

/etc/init.d/apache2 restart

But if you want to allow your client to PUSH (their COMMIT) into your repositories, you will have to change the folder access in order to allow www-data to write chown -R root.www-data /var/cache/git/test001 chmod -R g+w /var/cache/git/test001

Create /etc/apache2/sites-available/git for http://git.company.com (192.168.0.102) #The following commented lines are for a HTTPS server instead of unsecured HTTP #<IfModule mod_ssl.c> #<VirtualHost _default_:443> #SSLEngine on #SSLCertificateFile /etc/ssl/private/server.crt #SSLCertificateKeyFile /etc/ssl/private/server.key #SSLCertificateChainFile /etc/ssl/private/bundle.crt #if you uncomment the previous lines, also uncomment the last line of the file and comment the following one: <VirtualHost _default_:80>

Page 10: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

10

SetEnv GITWEB_CONFIG /etc/gitweb.conf SetEnv GIT_PROJECT_ROOT /var/cache/git SetEnv GIT_HTTP_EXPORT_ALL ServerName 192.168.0.102

DocumentRoot /usr/share/gitweb AliasMatch ^/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/cache/git/$1 AliasMatch ^/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/cache/git/$1 ScriptAliasMatch \ "(?x)^/(.*?)\.git/(HEAD | \ info/refs | \ objects/info/[^/]+ | \ git-(upload|receive)-pack)$" \ /usr/lib/git-core/git-http-backend/$1/$2 #ScriptAlias / /usr/share/gitweb/ <LocationMatch "^/.*?\.git/.*?$"> AuthType Basic AuthName "git repository" AuthUserFile /var/cache/git/htpasswd.git AuthGroupFile /var/cache/git/htgroup.git Require group cloners </LocationMatch> <LocationMatch "^/.*?\.git/git-receive-pack$"> AuthType Basic AuthName "git repository" AuthUserFile /var/cache/git/htpasswd.git AuthGroupFile /var/cache/git/htgroup.git Require group commiters </LocationMatch> <LocationMatch "^/test001\.git/.*?$"> AuthType Basic AuthName "git repository" AuthUserFile /var/cache/git/htpasswd.git AuthGroupFile /var/cache/git/htgroup.git Require group test001-read </LocationMatch> <LocationMatch "^/test001\.git/git-receive-pack$"> AuthType Basic AuthName "git repository" AuthUserFile /var/cache/git/htpasswd.git AuthGroupFile /var/cache/git/htgroup.git Require group test001-write </LocationMatch> <Directory /usr/share/gitweb/> Options ExecCGI FollowSymLinks Indexes Allow from all Order allow,deny AddHandler cgi-script cgi DirectoryIndex index.cgi RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^.* /index.cgi/$0 [L,PT] </Directory> </VirtualHost> #</IfModule>

And enable this site a2ensite git

Page 11: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

11

/etc/init.d/apache2 reload

Create the password file with a first user (chris) and choose a password for him htpasswd -c /var/cache/git/htpasswd.git chris

If you want to add a second user htpasswd /var/cache/git/htpasswd.git user2

Then create the following groups by creating the file /var/cache/git/htgroup.git vi /var/cache/git/htgroup.git test001-read:chris user2 user3 test001-write:chris user2 commiters:chris cloners:chris user2 user5

NB: cloners/commiters will have access to every repository except test001 which have its own groups test001-read/test001-write NB2: each write access must be allowed in couple with a read access (Write access does not work without read access) The folder must be writable by apache. An easy way to keep writing rights for CHRIS and Apache is: chown -R chris.www-data /var/cache/git/test001 chmod -R 770 /var/cache/git/test001

It should work, from now you have:

• Git Repository : http://192.168.0.102/test001.git/

Page 12: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

12

• Web Interface : http://192.168.0.102/test001/

• Web interface for all the repositories : http://192.168.0.102/git

8 Project über Eclipse erstellen und im Git Server ablegen Java Project, Class

Anbindung an Git:

Page 13: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

13

<Finish> Projekt in lokales Repository stellen: <Team/Commit> remote GIT Server definieren

Page 14: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

14

<Finish> <Advanced>

Page 15: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

15

<Finish>

Rechte Maustaste auf Origin:

Page 16: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

16

<Push>

<OK>

Page 17: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

17

9 Push / Commit Mit Eclipse

9.1 ? bei GIT is Fun hinzufügen

<Commit an Push>

<OK>

Page 18: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

18

9.2 Kontrolle in der Weboberfläche

<test001>

Page 19: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

19

<beispiel>

<src>

<GitTest.java>

Page 20: 2 Git Server Installation

Installation eine lokalen Git Servers Resch Andreas

20

10 Quellen http://www.thomas-krenn.com/de/wiki/Git_Server-Konfiguration http://www.blogix.net/2009/06/23/debian-archive-signing-keys-aktualisieren/ http://wiki.debian.org/SourcesList http://packages.debian.org/de/squeeze/git-all http://wiki.gonzofamily.com/a/Install_GIT_as_public_repository_on_Debian